I need a .NET regular expression that matches anything other than the exact full string match specified. So basically:
^Index$
... is the only exclusion I care about. Strings can start with, finish with or contain "Index", but not match exactly.
The answer must be via the pattern itself, as I am passing an argument to a third-party library and do not have control over the process other than via the Regex pattern.
This should do the trick:
^(?!Index$)
If a regular expression is a must,
Match match = Regex.Match(input, @"^Index$");
if (!match.Success){
// Do something
}
And with a horrible way
Match match = Regex.Match(input, @"^(.*(?<!Index)|(?!Index).*)$");
if (match.Success){
// Do something
}
Note: the second one is not tested, and the regular expression engine needs to support full look ahead and look behind.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With