Characters |
Character | Description | Example |
Any character except [\^$.|?*+() |
All characters except the special characters on the left match a single instance of themselves. { and } are literal characters, unless they're part of a valid regular expression token (e.g. the {n} quantifier). |
a matches a |
\ (backslash) followed by any of [\^$.|?*+(){} |
Escapes character to suppress the immediate following special character′ meaning. |
\+ matches + |
\Q...\E |
Matches the characters between \Q and \E literally, suppressing the meaning of special characters. |
\Q+-*/\E matches +-*/ |
\xHH where HH are 2 hexadecimal digits |
Matches HEX ASCII code of a character. |
\x21 matches ! |
\n, \r and \t |
Match LineFeed, Carrige Return and tab character respectively. |
\r\n matches a DOS CRLF. |
\a, \e, \f and \v |
Match printer/keyboard special characters: bell character (\x07), escape character (\x1B), form feed (\x0C) and vertical tab (\x0B) respectively. Can be found in ASCII code page. |
|
\cA through \cZ |
Match keyboard code Control+A through Control+Z, equivalent to ASCII code\x01 through \x1A. |
\cS\cQ matches a stop and go on keyboard. |
Character Sets [abc] |
Character | Description | Example |
[ (opening square bracket) |
Starts a character set. A character set contains all character within the range. |
|
Any character except ^-]\ can belongs to the character set. |
All characters except the special characters on the left. |
[abc] matches a, b or c |
\ (backslash) |
A escapes special characters to suppress the special meaning ofi ^-]\. |
[\^\]] matches ^ or ] |
- Hyphen |
Specifies a range of characters if placed between characters and numbers.
(represent a hyphen in the set, if placed immediately after [.) |
[a-z0-9] matches any lower case letter or digit |
^ Caret |
Negates the character set if placed immediately after [, if placed anywhere except after the opening [, represent the
caret belongs to the set |
[^A-C] matches any character except A, B, or C) |
Dot |
Character | Description | Example |
. Dot |
The most important shorthand character, matches any single character except line break characters \r and \n. |
. Matches any ONE character |
Anchors |
Character | Description | Example |
^ |
Matches at the beginning of the string. |
|
$ |
Matches the end of the string. |
|
\A |
Start the regular expression match from the beginning of the string. |
|
\Z |
Position the regular expression match to the end of the string. |
|
Word Boundaries |
Character | Description | Example |
\b |
This is a zero-width assertion that matches only at the beginning or end of a word. |
\bgreat\b matches only "great" is a compelete word exist |
\B |
Another zero-width assertion that is opposite the above. |
\Bhello\B success if there is no "hello" exist |
\w |
Matches any alphanumeric character or string, including "_". |
|
\W |
Matches any non-alphanumeric character or string. |
|
Alternation |
Character | Description | Example |
| |
Match possible correct answers. |
a (2|two)-year-old girl matches ether 2 or two, both are correct |
Quantifiers |
Character | Description | Example |
? |
Lazy quantifier. Matches the preceding pattern element zero or one times. |
xyz? matches xy or xyz |
* |
Matches the preceding pattern element zero or more times. Can not be placed at the first position
as match pattern, since it can not repeat nothing. |
".*" default WebMux match pattern to match anything in anylength |
+ |
Matches the preceding pattern element one or more times. |
"l+" If the URL contains "hello", it will be matched. |
+? None Greedy Match |
Modify the "+" regular expression to match as few time as possible. |
|
{n} An integer in curly brackets |
Repeats the preceeding character n times. |
t{3} return true if ttt exist |
{M,N} |
Denotes the minimum M and the maximum N match count. M,N must be > 0. |
l{1,2} matches Hello, World but not here |