DavidSzczesniak
12/20/2017 - 10:39 AM

Character classes

A brief overview. You can group multiple characters into a character class by enclosing them in square brackets. This allows you to treat a group of alternatives as a single atom.

# Basic character class
my $ascii_vowels = qr/[aeiou]/;
my $maybe_cat = qr/c${ascii_vowels}t/;

# The hyphen allows you to include a continous range of characters in a class:
my $ascii_letters_only = qr/[a-zA-Z]/;
# Alternatively, have the hyphen as a member of the class by placing it at the start or the end of the class:
my $interesting_punctuaction = qr/[-!?]/;
# or escape it:
my $line_characters = qr/[|=\-_]/;

# Use the caret(^) at the start of the class to mean 'anything except these characters'
my $not_an_ascii_vowel = qr/[^aeiou]/;