Regexp Character Classes
Regular expressions allow you to form character classes
of words using brackets [ and ]. For example, you can define a character class [Ff] that will match "F" or "f". You can also use character classes to accept ranges; for example, [A-Z] will accept all uppercase letters, [A-Za-z] will accept all letters, whether uppercase or lowercase, and [a-z0-9] will accept lowercase letters and numbers only. At the beginning of a character class, the caret symbol ^ means "not," therefore [^A-Z] will accept everything that is not an uppercase letter, and [^A-Za-z0-9] will accept symbols only—no uppercase letters, no lowercase letters, and no numbers.
There is a list of regular expressions using character classes, along with the string they match—and whether or not a match is made—in Table 15-2.
Table 15-2. Regular expressions using character classes
|
Function call |
Result |
|---|---|
|
|
True |
|
|
False; the regexp says "Anything that is not F or f, followed by "oo". This would match "too", "boo", "zoo", etc. |
|
|
True |
|
|
False; the acceptable range for the first character ends at S |
|
|
True; the range is inclusive |
|
|
False |
|
|
True |
|
|
False; case sensitivity! ... |