Perl regex / foo | bar / negation

时间:2012-05-11 07:52:18

标签: regex perl regex-negation

/\d/         # contains a digit
/^\D*$/      # doesn't contain a digit

/[abc]/      # contains either the letter a, b, or c
/^[^abc]*$/  # doesn't contain a, b, or c

/foo|bar/    # contains foo or bar
/???????/    # doesn't contain foo or bar

谁可以帮我这个?我找不到任何解决方案,但我需要一个正则表达式来否定没有任何可编程逻辑。

1 个答案:

答案 0 :(得分:9)

您可以使用否定前瞻断言:

/^(?!.*(?:foo|bar)).*$/    # doesn't contain foo or bar

See it