.Net Regular Expression - How to make an exact match exception for a full line?

I need a .Net regular expression that matches ANY OTHER than exact exact string matching is indicated. So basically:

^Index$

... this is the only exception that I care about. Lines can begin with, end with, or contain an "Index", but not exactly match. My brain today does not seem to work, and I cannot work on it.

EDIT

The answer SHOULD be through the template itself, since I pass the argument to a third-party library and do not control this process, except using the Regex template.

+5
source share
4 answers

This should do the trick:

^(?!Index$)
+5
source

Regex ,

Match match = Regex.Match(input, @"^Index$");

if (!match.Success){
    //do something
}

Match match = Regex.Match(input, @"^(.*(?<!Index)|(?!Index).*)$");

if (match.Success){
    //do something
}

: ,

+4

How about if (!r.Match("^Index$").Success) ...?

0
source

you can check !regex.Match.Success

0
source

All Articles