It seems the CR is not matched with [\s\S]
. Add \r
to this character class:
[\s\S\r]+
will match any 1+ chars.
Other alternatives that proved working are [^\r]+
and [\w\W]+
.
If you want to make any character class match line breaks, be it a positive or negative character class, you need to add \r
in it.
Examples:
- Any text between the two closest
a
andb
chars:a[^ab\r]*b
- Any text between
START
and the closestSTOP
words:START[\s\S\r]*?STOP
START[^\r]*?STOP
START[\w\W]*?STOP
- Any text between the closest
START
andSTOP
words:START(?:(?!START)[\s\S\r])*?STOP
See a demo screenshot below: