正则表达式包含和排除不带前瞻 [英] Regex to include and and exclude without lookahead

查看:104
本文介绍了正则表达式包含和排除不带前瞻的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想匹配包含foo和bar但不包含bar = 0的网址。我试图在Google中执行此操作分析,它不支持先行表达式。



因此,我匹配包含foo和bar的网址,该表达式为(foo 。+ bar)但是我如何用bar = 0否定网址?

解决方案

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

  \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

这篇关于正则表达式包含和排除不带前瞻的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆