Back to all tools
Regex Cheat Sheet
Review common regular expression tokens, anchors, groups, and flags.
When to use this tool
A quick reference for regex syntax including character classes, quantifiers, anchors, groups, and flags. Developers use it when writing or reviewing regular expressions to recall token meanings and behavior without leaving the browser.
How to use
Scroll through the categorized table of regex tokens.
Each row shows the command, a description of what it matches, and a practical example.
Use the search box to filter for specific tokens or concepts.
Character Classes
| Command | Description | Example |
|---|---|---|
.
|
Any character except newline. |
/c.t/ matches cat, cot, cut
|
\d
|
Any digit from 0 to 9. |
/\d{3}/ matches 123
|
\D
|
Any non-digit character. |
/\D+/ matches abc
|
\w
|
Any word character: letter, digit, or underscore. |
/\w+/ matches user_1
|
\W
|
Any non-word character. |
/\W/ matches !
|
\s
|
Any whitespace character. |
/a\sb/ matches a b
|
\S
|
Any non-whitespace character. |
/\S+/ matches text
|
[abc]
|
One character from the listed set. |
/[aeiou]/ matches a vowel
|
[^abc]
|
One character not in the listed set. |
/[^0-9]/ matches A
|
Quantifiers
| Command | Description | Example |
|---|---|---|
*
|
Zero or more of the previous token. |
/ab*/ matches a, ab, abb
|
+
|
One or more of the previous token. |
/ab+/ matches ab, abb
|
?
|
Zero or one of the previous token. |
/colou?r/ matches color and colour
|
{3}
|
Exactly three repetitions. |
/\d{3}/ matches 123
|
{2,5}
|
Between two and five repetitions. |
/\w{2,5}/ matches token lengths 2-5
|
{2,}
|
Two or more repetitions. |
/a{2,}/ matches aa, aaa
|
Anchors
| Command | Description | Example |
|---|---|---|
^
|
Start of string, or start of line with multiline mode. |
/^Hello/ matches Hello at the start
|
$
|
End of string, or end of line with multiline mode. |
/done$/ matches text ending in done
|
\b
|
Word boundary. |
/\bcat\b/ matches cat as a word
|
\B
|
Position that is not a word boundary. |
/\Bcat\B/ matches scatter
|
Groups and Alternation
| Command | Description | Example |
|---|---|---|
(abc)
|
Capturing group. |
/(foo)/ captures foo
|
(?:abc)
|
Non-capturing group. |
/(?:http|https):\/\// matches a protocol
|
(?<name>abc)
|
Named capturing group. |
/(?<year>\d{4})/ captures year
|
a|b
|
Match the left or right alternative. |
/cat|dog/ matches cat or dog
|
Flags
| Command | Description | Example |
|---|---|---|
g
|
Find all matches in JavaScript. |
/test/g
|
i
|
Case-insensitive matching. |
/hello/i matches Hello
|
m
|
Multiline anchors for ^ and $. |
/^item/m matches item at a line start
|
s
|
Dot matches newline characters. |
/a.*b/s matches across lines
|
u
|
Unicode-aware matching. |
/\p{Letter}+/u matches letters
|