\n | newline |
\t | tab |
\s | whitespace (space, tab, or newline) |
\S | non-whitespace |
\w | word character (letter, number, or underscore) |
\W | non-word character (anything other than letter, number, or underscore) |
\b | word boundary |
\B | non-word boundary |
\d | digit |
\D | non-digit |
^ | beginning of line |
$ | end of line |
| |
. | single character wildcard |
| | an or relationship between two patterns (/me|you/) |
(abc) | treats abc as a single unit (for quantifiers), and stores it in \1 and $1 |
(?:abc) | treats abc as a single unit (for quantifiers), but does not store it |
(?=abc) | matches abc without including it in the matched string (for picky backreferences or substitutions-- for example, s/abc(?=def)/xyz/ will substitute 'xyz' for any occurrence of 'abc' which is followed by 'def', without clobbering the 'def') |
(?!abc) | matches anything other than 'abc', without including that text in the mathed string |
\1 \2 | backreference to the first, second, and so on, already matched parenthesized group (for example /(h.) \1 \1/ would match 'ha ha ha') |
[abc] | one of any of the enclosed characters |
[a-z] | one of any of the range of enclosed characters |
[^abc] | anything other than the specified characters |
| |
$1, $2 | (Perl variable) text matched in the first, second, and so on, back reference (parenthesized expression) |
$& | (Perl variable) text matched in last pattern match |
$` | (Perl variable) text before the matched pattern in the source string |
$' | (Perl variable) text after the matched pattern in the source string |
$+ | (Perl variable) contents of last successful back reference (parenthesized expression) -- useful if multiple
back references are set, and you don't know whether to address $1 or $2 |