且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

正则表达式包含和排除不带前瞻

更新时间:2022-11-14 18:46:08

可以使用这个正则表达式:

  \bfoo\b。+ \bbar\b(?:$ | = [ ^ b 

现场演示: http://www.rubular.com/r/marUIfFzAz


I want to match a URL containing both "foo" and "bar" but not "bar=0".

I'm trying to do this in Google Analytics and it doesn't support lookahead expressions.

So I am matching urls containing both "foo" and "bar" with this expression (foo.+bar) but how do I negate urls with "bar=0"?

You can use this regex:

\bfoo\b.+\bbar\b(?:$|=[^0]|[^=])

Live Demo: http://www.rubular.com/r/marUIfFzAz