Regular expressions are patterns to be matched against some target string of text. They may include metacharacters (also known as wildcards) that allow a broader scope of possible matches.
Here is a list of the more commonly used metacharacters:
| . | (The period or "dot".) Matches any one character (except a "newline"). |
| [aeoui] | A character class; matches one of the characters between the square brackets. |
| [^1357] | A negated character class (indicated by the leading ^). Matches any character except one of the characters between the aquare brackets and after the ^. |
| [0-9] | The - indicates an ASCII range. This example is equivalent to [0123456789]. |
| abc|xyz | The | is the alternation operator. This example means "either abc or xyz". |
| x* | The * is the zero or more multiplier. This example means "0 or more x(s) in sequence". |
| .* | .* is the most popular use of *. This combination of . and * means "0 or more any character(s) in sequence (except newline characters)". |
| x+ | The + is the one or more quantifier. This example means "1 or more x(s) in sequence". |
| x? | The ? is the zero or one quantifier. This example means "0 or 1 x". |
| x{10} | The {} are used to represent general quantifiers. This example means "10 x(s) in sequence". |
| x{10,} | This example means "10 or more x(s) in sequence". |
| x{10,30} | This example means "10 or more but no more than 30 x(s) in sequence". |
| ^Begin | ^ as the first character means "string begins with". This example means "begins with Begin". |
| end$ | $ as the last character means "string ends with". This example means "ends with end". |
| Perl shortcuts*: | |
|---|---|
| \d | Shortcut for "a digit". |
| \D | Shortcut for "NOT a digit". |
| \w | Shortcut for "a word character" (equivalent to [A-Za-z0-9_]). |
| \W | Shortcut for "NOT a word character". |
| \s | Shortcut for "a space character" (equivalent to a class including space, tab, new line, carriage return and form feed characters). |
| \S | Shortcut for "NOT a space character". |
| \bBACH\b | Shortcut for "a word boundary". This example would find BACH but would NOT find OFFENBACH. |
| \B | Shortcut for "NOT a word boundary". |