Match opposite of regular expression
I have a quick question about Regular Expressions.
Can I specify a pattern and have everything else that doesnt开发者_开发百科 fit the pattern to be matched?
For example, anything that does not fit into this pattern: HT\d{4}
, I want to consider a match.
yes, you can do this: (?!HT\d{4})
It's called a "negative lookahead". It is supported in most regex engines.
You can do something like ^.*$(?<!HT\d{4})
But in most languages, you can use the original regex and use a logical !
in the language. Like !Regex.IsMatch()
精彩评论