Reputation: 1688
How do I write a .net regex which will match a string that does NOT start with "Seat"
Upvotes: 6
Views: 1706
Reputation: 38356
I would suggest not doing it. You should be able to just get every string that doesn't match.
!Regex.IsMatch("^Seat.*", string);
Upvotes: 0
Reputation: 91635
What you're looking for is:
^(?!Seat).+
This article has more information about look aheads.
Upvotes: 11
Reputation: 755387
Writing a regex for a "does not start with" can be a little tricky. It's often easier to write a regex to detect that a string starts with a substring and not the match instead.
For Example:
return !Regex.IsMatch("^Seat.*", input);
Upvotes: 7