[英]Regular Expression => Match Everything from Set, except one character
假设我有一组字符[az]我想匹配集合中的每个字符,除了字符“a”谢谢!
[a-z-[e]]
means "any character between a and z except e". 表示“除了e之外的a和z之间的任何字符”。 But as far as I know, only .NET, JGSoft and XML Schema support these " subtracted character classes ".
但据我所知,只有.NET,JGSoft和XML Schema支持这些“ 减去字符类 ”。
Another example: 另一个例子:
[a-z-[aeiou]]
matches any (ASCII) consonant. 匹配任何(ASCII)辅音。
You can specify the character ranges as you want, for example: 您可以根据需要指定字符范围 ,例如:
[b-z]
This will only match the character from b
to z
. 这只会匹配从
b
到z
的字符。 The only restriction is that it's a valid character range according to the character set that is used so that the first character has a lower code point than the second character. 唯一的限制是,根据使用的字符集,它是一个有效的字符范围,以便第一个字符的代码点低于第二个字符。
Complete solution (ie no matter where the character is located in the [az] set and much more compatible): 完整的解决方案(即无论在哪里字符位于[AZ]设置以及更多兼容):
[^\W\dA-Z && x]
Where "x" is the character (or group of characters, eg efgh) you want to exclude. 其中“x”是您要排除的字符(或字符组,例如efgh)。
Tested on: 测试:
http://www.regexplanet.com/advanced/java/index.html http://www.regexplanet.com/advanced/java/index.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.