Gainesville Perl Mongers
Home of the orange & blue camel

Home | Members | Perl tutorials | Mailing List | Merchandise | links

Regular Expressions: Symbols and Modifiers

Symbols you can use in pattern matching:

SymbolWhat it matches
.Matches any single character except newline
[a-z0-9]Matches any single charecter of set
[^a-z0-9]Matches any single charecter NOT in set
\dMatches a digit (a number 0-9)
\DMatches a non-digit (anything but 0-9)
\wMatches an alphanumeric charecter (a-zA-Z0-9 and _)
\WMatches a non-alphanumeric charecter
\sMatches a whitespace character (space, tab, newline)
\SMatches a non-whitespace character
\nMatches a newline
\rMatches a return
\tMatches a tab
\fMatches a formfeed
\bMatches a backspace (inside [] only)
\0Matches a null character
\bMatches a word boundary (outside [] only)
\BMatches a non-word boundary
^Anchors match to the beginning of a line or string
$Anchors match to the end of a line or string

x?Matches 0 or 1 x's, where x is any of the above
x*Matches 0 or more x's
x+Matches 1 or more x's
x{m,n}Matches at least m x's, but no more than n
(pat1|pat2)Matches either pat1 or pat2
(pat)Stores a pattern for backreferencing via $1, $2 through $9
Note: All other characters match themselves, except for these special characters: + ? / * ^ $ @ () [] | \ To match one of these, you have to use a backslash (e.g. "\@" matches "@").

m//, s//, and qr// operators all except the following modifiers after their delimiter:

/iIgnore alphabetic case distinctions (case insensitive)
/sLet . match newline and ignore deprecated $* variable
/mLet ^ and $ match next to embedded \n
/xIgnore (most) whitespace and permit comments in pattern
/oCompile pattern once only

s// specific modifiers:

/gReplace globally, that is, all occurrences
/eEvaluate the right side as an expression