正则表达式匹配一个没有跟在其他两个词之后的词 [英] Regex match a word not followed by two other words

查看:33
本文介绍了正则表达式匹配一个没有跟在其他两个词之后的词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些链接:

utmcsr=rdstation|utmccn=curso-intro-coaching|utmcmd=inbound|utmctr=link3
utmcsr=rdstation|utmccn=agenda-psc|utmcmd=email
utmcsr=rdstation|utmccn=pnl-porto-alegre

我想构建一个与 rdstation 匹配的正则表达式,后跟 inbound OR email.

I want to build a regex expression that matches the rdstation not followed by inbound OR email.

我试过 rdstation(?!(email|inbound)) 但没有用.

推荐答案

问题是你的负前瞻直接锚定在 rdstation 之后的位置.它只会排除这样的字符串:

The problem is that your negative lookahead is anchored to the position directly after rdstation. It would only exclude strings like this:

rdstationemail asdf 123 4

你需要确保它可以在 rdstation 之后的任何地方匹配:

You need to make sure it can match anywhere after rdstation:

rdstation(?!.*(email|inbound))

此处的工作示例.

这篇关于正则表达式匹配一个没有跟在其他两个词之后的词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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