Help on Perl Regular Expressions

Most characters in a regular expression match themselves. However, some characters have special meanings. The table below lists some of the more useful special (meta) characters.
Reg-expr   | Description
-----------+---------------------------------------------------
.          | Matches any character (except newline)
^          | Matches the start of the string
$          | Matches the end of the string
x?         | Matches 0 or 1 x's, where x is any regular expression
x*         | Matches 0 or more x's
x+         | Matches 1 or more x's
foo|bar    | Matches one of foo or bar
[xyz]      | Matches any character in the set xyz, specify ranges with a -
[^xyz]     | Matches any single character not in the set xyz
\w         | Matches an alpha-numeric character, i.e., [a-zA-Z0-9_]
\s         | Matches a whitespace character
\b         | Matches a word boundary
(x)        | Brackets a regular expression
\metachar  | Matches the metacharacter (takes away its special meaning)

Examples

Full details on Perl regular expressions can be found in the Perl manual.


Last modified 23 Oct 2003.
Comments emailed to andrew.dowsey@imperial.ac.uk welcomed.