正则表达式排除在某个子字符串之前存在的子字符串

can*_*out 2 ruby regex

有关如何编写匹配子串"紧急"的正则表达式的任何想法,只要它在'紧急'之前不包含'not'吗?

恩.

this is urgent- 比赛!
[not urgent] blah - 不匹配

对于Ruby 1.9.2,这是 /(?<!not )urgent/ 有用的 - 使用负面看后面

man*_*lds 7

您可以使用以下正则表达式:

/(?=.*urgent)(?!.*not urgent)(^.*$)/
Run Code Online (Sandbox Code Playgroud)

样本匹配:http://regexr.com?2trsp