正则表达式无需提前就可以包含和排除 [英] Regex to include and exclude without lookahead

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

问题描述

我想匹配同时包含"foo"和"bar"但不包含"bar = 0"的URL.

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

我正在尝试在Google Analytics(分析)中执行此操作,它不支持超前表达式.

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

所以我要用表达式(foo.+bar)匹配同时包含"foo"和"bar"的网址,但是如何用"bar = 0"取反网址?

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]|[^=])

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

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