如何匹配不包含模式的字符串

时间:2014-11-17 14:54:20

标签: c# regex negative-lookahead negative-lookbehind

我正在尝试编写一个匹配所有不包含某个模板的字符串的正则表达式模板。

例如:

匹配:

This is my friend. He is very nice. 

This is my friend. He is very nice. 

但与以下内容不匹配:

  This is my friend John Michaels Fredrickson. He is very nice. 

因为它包含这样的内容:([A-Z] [a-z] + \ s?){3}

1 个答案:

答案 0 :(得分:1)

您可以使用否定前瞻:

^(?!.*?([A-Z][a-z]+\W){3}).*$

RegEx Demo