我有一个正则表达式模式
^(\d+|\w+-\d+)$
如何匹配所有与此模式不匹配的字符串?
最佳答案
如果你研究一下并尝试理解这一点。按道理来说,会是这样的。假设有一个条件为 X
或 Y
,那么其否定既不是 X
也不是 Y
>.
X 或 Y
否定
将等于 Neither X and Nor Y
.
为此,您可以尝试一下。
正则表达式: ^(?!\d+$)(?!\w+-\d+$).*$
1.
^
start of string.2.
(?!\d+$)
negative look-ahead for digits till the end of string.3.
(?!\w+-\d+$)
negative look-ahead forwords
then-
and thendigits
till the end.4.
.*$
match all till then end.
关于regex - 使用 OR `|` 时对正则表达式求反,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44061889/