Regular Expressions QuickStart
Wildcards

. Any single character except a line break, including a space.
* Zero or more characters
+ One or more characters.
? Zero or one characters.
 
^ Beginning of a line (unless used in a character class. see below)
$ End of a line (unless used in a character class. see below)
 
Character Class

[aeiou] Any of the characters a, e, i, o, i.
[^aeiou] Any characters except a, e, i, o, i.
[a-e] Any character in the range a-e, inclusive.
[a-zA-Z0-9] Any alphanumeric character
[[] Finds a [.
[]] Finds a ].
[a-e^] Finds a character in the range a-e or the caret character. To find the caret character place it anywhere except as the first character after the bracket.
[a-e-] Finds a character in the range a-e or the - sign. To find a - sign, place it at the end or the beginning of the set.
 
Special characters (non printing characters)

\r Line break (return)
\n Newline (linefeed)
\t Tab.
\f Formfeed (page break)
\xNN Hex code NN.
 
\s Any whitespace character (space, tab, return, linefeed, formfeed).
\S Any non-whitespace character.
\w Any "Word" character (a-z, A-Z, 0-9, and _).
\W Any "non-Word" character (All characters not included by \w).
\d Any digit (0-9); Same as #.
\D Any non-digit character.
 
Extension mechanism: (?#text)

(?:pattern) For grouping without backreference.
(?=pattern) A zero-width positive look-ahead assertion. For example, \w+(?=\t) matches a word following by a Tab.
(?!pattern) A zero-width negative look-ahead assertion. For example foo(?!bar) matches any occurence of "foo" that isn't followed by "bar".
(?>=pattern) A zero-width positive look-behind assertion. For example, (?>=\t)\w+ matches a word that follows a Tab. Works only for fixed-width look-behind.
(?>!pattern) A zero-width negative look-behind assertion. For example, (?>!bar)foo matches any occurence of "foo" that does not follow "bar". Works only for fixed-width look-behind.
 
Combining patterns

###\s###-#### Matches phone number of the form "xxx xxx-xxxx".
\($###\)?\s###-#### Matches phone numbers of the forms "(xxx) xxx-xxxx" or "xxx xxx-xxxx".
\$?[0-9,]+\.#* Matches dollar amounts with an optional dollar sign.
#+\sB\.C\. One or more digits followed by a space, followed by "B.C."
 
Alternation Operator

\she\s|\sshe\s " he " or " she ".
cat|dog|possum "cat", "dog" or "possum".