Regex match a word not followed by two other words

2020-05-07 04:26发布

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条回答
男人必须洒脱
2楼-- · 2020-05-07 04:50

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.

查看更多
登录 后发表回答