2
/\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

谁能帮我解决这个问题?我找不到任何解决方案,但我需要一个正则表达式来否定它,而无需任何可编程逻辑。

4

1 回答 1

9

您可以将否定前瞻断言用作:

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

看见

于 2012-05-11T07:58:42.430 回答