Regex matching multiple negative lookahead

2019-02-16 15:46发布

I'm trying to match a string (using a Perl regex) only if it doesn't start with "abc:" or "defg:", but I can't seem to find out how. I've tried something like

^(?:(?!abc:)|(?!defg:))

7条回答
Rolldiameter
2楼-- · 2019-02-16 16:28

Lookahead (?=foo), (?!foo) and lookbehind (?<=), (?<!) do not consume any characters.

You can:

^(?!abc:)(?!defg:).*

or

^(?!defg:)(?!abc:).*

The order does not make a difference.

查看更多
登录 后发表回答