开发者

Match opposite of regular expression

开发者 https://www.devze.com 2023-03-06 07:41 出处:网络
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?

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()

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号