Regex 如何排除字符串

Regex 如何排除字符串,regex,Regex,我想从消息中排除字符串“VSS” VSS写入程序内存不足 我用于模式匹配的正则表达式是 [O,o]ut of [M,m]emory 但是如果VSS出现在消息中,我想排除整个消息。这可能吗?您可以使用负片解决此问题: 说明: (?i) # Make the regex case-insensitive ^ # Match the start of the string (?!.*VSS) # Assert that there is no

我想从消息中排除字符串“VSS”

VSS写入程序内存不足

我用于模式匹配的正则表达式是

[O,o]ut of [M,m]emory

但是如果VSS出现在消息中,我想排除整个消息。这可能吗?

您可以使用负片解决此问题:

说明:

(?i)           # Make the regex case-insensitive
^              # Match the start of the string
(?!.*VSS)      # Assert that there is no "VSS" in the string
.*             # Match any number of characters
out of memory  # Match "out of memory"

顺便说一句,
[O,O]
O
O
匹配,所以这可能不是您的意思。

您可以使用负数:

说明:

(?i)           # Make the regex case-insensitive
^              # Match the start of the string
(?!.*VSS)      # Assert that there is no "VSS" in the string
.*             # Match any number of characters
out of memory  # Match "out of memory"

顺便说一下,
[O,O]
O
O
匹配,所以这可能不是您的意思。

字符类中的逗号不是语法的一部分。它们将匹配逗号。它们应该被移除。我试图编辑文章,但无法编辑,因为“编辑内容必须至少包含6个字符”。(对这样的任意规则来说是的。)字符类中的逗号不是语法的一部分。它们将匹配逗号。它们应该被移除。我试图编辑文章,但无法编辑,因为“编辑内容必须至少包含6个字符”。(这类武断的规则太棒了。)