regex breaks on \n
segmentText = ;
testRgx = [/( \d+\.| [^\W\d_]\.|.)+?([!?.。](?= |$)|$)/g];
arrSegments = segmentText.match(testRgx);
This expression fails if segmentText has \n or other white spaces in it.I want to add \n in to the list of chars tha开发者_StackOverflow社区t the above pattern use [!?.。] => [!?.。\n] so that the segment is separated based on the \n character
If you add the 'm' modifier the . will match newlines
/foo/gm
In javascript there is no 's' modifier, so for instance if you want to match things inside quotes in the following text:
something foo bar "
porky" something bar foo
You could normally use /".+?"/s
. Instead in JS you would use /"[\s\S]+?"/
- matching every character, as the dot will match all but newline characters.
精彩评论