C# Regex to match a string that doesn't contain a certain string?

Shaul Behr picture Shaul Behr · Aug 23, 2009 · Viewed 57.7k times · Source

I want to match any string that does not contain the string "DontMatchThis".

What's the regex?

Answer

Kamarey picture Kamarey · Aug 23, 2009

try this:

^(?!.*DontMatchThis).*$