Regular Expressions: Matching
 
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.

Index
Introduction
What Is Perl?
Perl Resources
Running a Perl Program
Perl Thinking
Data Types
Scalars
Strings: Single Quoted
Strings: Double Quoted
Scalar operations
Scalar comparisons
Variables
Lists
Using Lists
Control Structures
Hashes
Hash Manipulation
File Handling
Regex Matching
Regex Matching: Ex. 1
Regex Matching: Ex. 2
Regex Replacing
Subroutines
Anonymous subs
References
Structures
Modules
Modules: File::Find
Modules: Internet
Modules: Win32::*
Everything Else
  Next page >>>