October 2017
Intermediate to advanced
440 pages
11h 47m
English
Character class subtraction is supported by .NET (and PowerShell). Character class subtraction is not commonly used at all.
Inside a character class, one character class may be subtracted from another (reducing the size of the overall set). One of the best examples of this extends to the character class containing vowels. The following matches the first vowel in a string:
'The lazy cat sat on the mat' -match '[aeiou]'
To match the first consonant, one approach can be to list all of the consonants:
'The lazy cat sat on the mat' -match '[b-df-hj-np-tv-z]'
Another approach to the problem is to take a larger character class, then subtract the vowels:
'The lazy cat sat on the mat' -match '[a-z-[aeiou]]'
Read now
Unlock full access