- Regexes are their own mini-language
- Match letters, numbers, other characters
- Exclude certain characters from matches
- Character classes (in []) denote a possible set
of characters to match
- Negate a character classes with a carat ([^abc])
- Provided character classes include:
- \d, \D for digits, non-digits
- \w, \W for word and non-word characters
(letters, digits, underscore)
- \s, \S for white-space and non-space characters
- . for any character except newline
my $string = "Did the fox jump over the dogs?";
print "1: $string\n" if $string =~ m/[bdl]og/; # bog, dog, log
print "2: $string\n" if $string =~ m/dog[^s]/; # no match
print "3: $string\n" if $string =~ m/\s\w\w\wp\s/; # matches
|