I am trying to split sentences with some exceptions to ignore cases like Mr. And Mrs. Etc… And add them to an array.
This worked in vanilla JS for me
/(?<!sMrs)(?<!sMr)(?<!sSr)(.s)|(!s)|(?s)/gm
Unfortunately React Native doesn’t support the negative lookbehind.
Is there another way I can achieve the same result?
2
Answers
I ended up doing this:
If anyone has a more efficient solution, let me know!
You can create exceptions in the following way:
The regex (see its online demo) matches
(?:b(?:Mrs?|Sr).s|[^!?.])+
– one or more occurrences ofb(?:Mrs?|Sr).s
–Mr
,Mrs
orSr
as whole words followed with.
and a whitespace char|
– or[^!?.]
– any single char other than?
,!
and.
[!?.]?
– an optional!
,?
or.
.