Character Class Subtraction

Character class subtraction is supported by the XML SchemaXPath.NET (version 2.0 and later), and JGsoftregex flavors. It makes it easy to match any single character present in one list (the character class), but not present in another list (the subtracted class). The syntax for this is [class-[subtract]]. If the character after a hyphen is an opening bracket, these flavors interpret the hyphen as the subtraction operator rather than the range operator. You can use the full character class syntax within the subtracted character class.
The character class [a-z-[aeiuo]] matches a single letter that is not a vowel. In other words: it matches a single consonant. Without character class subtraction or intersection, the only way to do this would be to list all consonants: [b-df-hj-np-tv-z].
The character class [\p{Nd}-[^\p{Thai}]] matches any single Thai digit. The base class matches any Unicode digit. All non-Thai characters are subtracted from that class. [\p{Nd}-[\P{Thai}]] does the same.[\p{Thai}-[^\p{Nd}]] and [\p{Thai}-[\P{Nd}]] also match a single Thai digit by subtracting all non-digits from the Thai characters.

Post a Comment