September 2017
Beginner
402 pages
9h 52m
English
A character class is a mechanism to request a match with a given list of characters. For example, to match hexadecimal numbers, we need to match a character with decimal digits 0 to 9 and with six letters a to f (also including their capital variants A to F).
In Perl 6 regexes, this can be written as a character class <[0..9 a..f A..F]>. Let us apply this regex to the list of uppercase Latin letters:
for 'A'..'Z' { .print if /<[0..9 a..f A..F]>/;}
This prints the string ABCDEF, containing the letters that match the given regex.
Character classes may also include backslashed sequences. In the phone number regex, we can use a character class that will match with either a digit, a space, or a hyphen:
/ \+? <[\d\s\-]>+ /;