代码之家  ›  专栏  ›  技术社区  ›  user7784919

C#Regex匹配不包含特定字符串的不区分大小写的字符串[重复]

  •  0
  • user7784919  · 技术社区  · 8 年前

    我想匹配任何不包含字符串“None”的字符串(不区分大小写的匹配),

    我提到了这个问题 C# Regex to match a string that doesn't contain a certain string?

    上述问题给出了区分大小写的解决方案,但我需要禁止使用字符串 无论如何,“无”。

    我需要一个通用正则表达式来禁止字符串(不区分大小写的匹配)。

    例如:

    • 没有一个
    • 没有一个
    • 没有一个
    • 无等。,

    1 回复  |  直到 8 年前
        1
  •  5
  •   Derek    8 年前

    使用RegexOptions.IgnoreCase:

    Regex.Matches( text, @"^(?!.*None).*$", RegexOptions.IgnoreCase );
    Regex.IsMatch( text, @"^(?!.*None).*$" , RegexOptions.IgnoreCase );
    
    推荐文章