我无法找到一种方法,使正则表达式匹配停止不在行结束,但在文件结束的 VS 代码?这是一个工具的限制,还是有某种我没有意识到的模式?
It seems the CR is not matched with [\s\S]. Add \r to this character class:
[\s\S]
\r
[\s\S\r]+
will match any 1+ chars.
Other alternatives that proved working are [^\r]+ and [\w\W]+.
[^\r]+
[\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:
a
b
a[^ab\r]*b
START
STOP
START[\s\S\r]*?STOP
START[^\r]*?STOP
START[\w\W]*?STOP
START(?:(?!START)[\s\S\r])*?STOP
See a demo screenshot below:
To matcha multi-line text block starting from aaa and ending with the first bbb (lazy qualifier)
aaa
bbb
aaa(.|\n)+?bbb
To find a multi-line text block starting from aaa and ending with the last bbb. (greedy qualifier)
aaa(.|\n)+bbb