Regex Quick Reference






4.53/5 (14 votes)
A convenient Regex overview.
Characters - single character of a certain type
\w |
word character |
\W |
non-word character |
\d |
digit |
\D |
non-digit |
\s |
whitespace |
\S |
non-whitespace |
\r |
carriage return |
\n |
line feed |
\t |
tab |
[\b] |
backspace |
\x00[1] |
character by hex value |
|
Quantifiers - specify number of times to match
? |
zero or one |
{n[2]} |
n times |
* |
zero or more |
{n[3],} |
n or more times |
+ |
one or more |
{n[4], m} |
n to m times |
Ranges - specify a range of accepted values
[ abc ] |
a,b, or c |
[^ abc ] |
not a,b, or c |
[a-c] |
a, c, or anything in between |
a|c |
either a or c |
Anchors - specify a certain position to match
\b |
word boundary |
\B |
not word boundary |
\< |
start of word |
\> |
end of word |
^ |
start of line |
$ |
end of line |
Assertions - match a pattern without consuming
(?=pat[5]) |
positive look-ahead |
(?!pat) |
negative look-ahead |
(?<=pat) |
positive look-behind |
(?<!pat) |
negative look-behind |
Groups - multiple characters grouped together
(pat) |
group with back-reference |
(?<name>pat) |
group with named back-reference |
\n[6] |
refer to a back-referenced group |
(?:pat) |
group without back-reference |
Modifiers - specify how the regex engine searches
(?i:pat) |
case insensitive |
(?-i:pat) |
case sensitive |
(?s:pat) |
dot matches newline |
(?-s:pat) |
dot does not match newline |
(?x:pat) |
ignore pattern spacing |