Regex to include and exclude without lookahead

一曲冷凌霜 提交于 2019-12-08 09:00:12

问题


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"?


回答1:


You can use this regex:

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

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




回答2:


foo.+bar[^\=]

for this to make any sense, please post a example of a url you are trying to validate



来源:https://stackoverflow.com/questions/18332696/regex-to-include-and-exclude-without-lookahead

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!