Patterns
- Regexes match against a string using a pattern.
- Matches match against $_
by default
- Use $var =~ m/pattern/
to match against a given var
| Regular
Expression Patterns |
| . |
Matches any single character |
| * |
Zero or more |
| + |
One or more |
| ? |
Zero or one |
| [aeiou] |
Character class (here, the vowels) |
| ^ |
Beginning of the line |
| $ |
End of the line |
| \b |
Word boundary |
| \d \D |
Matches a digit/non-digit |
| \s \S |
Matches a space/non-space |
| \w \W |
Matches a word character/non-word character |
| | |
Separates subexpressions to match |
| () |
Grouping |
| Regular
Expression Examples |
| \d\d\d-\d\d\d\d
|
Basic phone number |
| (\d\d\d-)?\d\d\d-\d\d\d\d
|
Phone number with optional area code |
| \b[aeiou]\w+ |
A word beginning with a vowel |
| ^(Error|Warning).+(\d+)$ |
Line starting with "Error" or "Warning", and ending with a
series of digits. | |
|
|