Hi ! Let say I have set of characters [a-z] I want to match every character from the set, except character "a" Thanks !
+3
A:
You can specify the character ranges as you want, for example:
[b-z]
This will only match the character from b
to 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.
Gumbo
2010-10-03 17:56:53
Hi ! I figured that [b-z] is simplest solution. But what if I would want something in the middle of alphabet ? [a-df-z] for letter except "e". I am looking for something direct.
2010-10-03 18:31:16
@user465292: That is the most comprehensive way. Another way would be to use [look-around assertions](http://www.regular-expressions.info/lookaround.html), e.g. `(?!e)[a-z]` (look-ahead) or `[a-z](?<!e)` (look-behind). But those are not supported by every regular expression library.
Gumbo
2010-10-03 18:38:24
A:
[a-z-[e]]
means "any character between a and z except e". But as far as I know, only .NET, JGSoft and XML Schema support these "subtracted character classes".
Another example:
[a-z-[aeiou]]
matches any (ASCII) consonant.
Tim Pietzcker
2010-10-03 18:39:17