C# Regular Expression to Match Everything But...




If you dabble into Regex-driven processing, this one can come in handy. For those of us who don't consider Regular Expressions regularly (ba-dum-tshh), coming up with one from scratch can take a little time... but I digress.

This particular regular expression should result in a match for all inputs, except those containing the specified string:

 

^((?!ipsum).)*$

 

The expression above will return a match for all inputs, except those that contain letter sequence 'ipsum'. 

Salt and pepper to taste, test it here.

Cheers!

 



User login