Symbol | Matches: | |
\t |
Tab character. | |
\n |
Newline character. | |
\\ |
Back slash character. | |
\w |
Any "word" character: letters, digits, or underscore (_). | |
\W |
Any "non-word" character | |
\s |
Any white-space character: space, tab, newline, etc. | |
\S |
Any non-white-space character. | |
\d |
Any digit. | |
\D |
Any non-digit. | |
\b |
Any word boundary: a point in the string between a word and non-word character. | |
\B |
Any non-word boundary: a point in the string between two characters that are both word characters, or are both non-word. | |
. |
Any character. | |
^ |
The beginning of the string. | |
$ |
The end of the string. | |
Note: the backslash character may be used before special pattern characters such as ^, $, etc. in order to override their special meanings. For example, a dash (-) is a special character in patterns. To actually match a dash, use \-. |
Pattern component | Matches |
P|Q |
Either P or Q, where P and Q are patterns. |
P+ |
One or more consecutive occurences of pattern P. |
P* |
Zero or more consecutive occurences of pattern P. |
P? |
Zero or one occurence of pattern P. |
P{n} |
Exactly n consecutive occurences of pattern P. |
P{n,} |
At least n consecutive occurences of pattern P. |
P{n,m} |
At least n, and at most m, consecutive occurences of pattern P. |
[aeiou] |
Any one of the characters a, e, i, o, or u (lowercase). |
[a-z] |
Any lower case letter. |
[0-9] |
Any digit. |
Modifier | Purpose |
i | Case-insensitive searching |
g | Global replace (works only with replace()) |