Regex match a word not followed by two other words

大憨熊 提交于 2020-02-16 11:31:42

问题


I have some links:

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

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

I've tried rdstation(?!(email|inbound)) but it doesn't worked.


回答1:


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

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

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

Working example here.



来源:https://stackoverflow.com/questions/44204359/regex-match-a-word-not-followed-by-two-other-words

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