正则表达式可以匹配除字符列表以外的所有内容 [英] Regex to match everything except a list of characters

查看:91
本文介绍了正则表达式可以匹配除字符列表以外的所有内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想匹配包含除指定字符 [I | V | X | M | C | D | L] 之外的所有内容的行.

I want to match a line containing everything except the specified characters [I|V|X|M|C|D|L].

new Regex(@"^(.*) is (?![I|V|X|M|C|D|L].*)$")

应匹配除 OR 列表中提到的字符以外的所有内容.

should match everything except the characters mentioned in the OR list.

应该匹配-

name is a

不匹配-

edition is I

推荐答案

尝试以下模式:

^[^IVXMCDL]*$

这将匹配字符串的开头,然后是零个或多个字符(不是在字符类中指定的字符),然后是字符串的末尾.换句话说,它将不匹配包含这些字符的任何字符串.

This will match the start of the string, followed by zero or more characters other than those specified in the character class, followed by the end of the string. In other words, it will not match any a string which contains those characters.

还要注意,根据您的使用方式,您可能会使用以下更简单的模式:

Also note that depending on how you're using it, you could probably use a simpler pattern like this:

[IVXMCDL]

并拒绝任何与模式匹配的字符串.

And reject any string which matches the pattern.

这篇关于正则表达式可以匹配除字符列表以外的所有内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆