Regular expressions are compact patterns for matching text, but the syntax is easy to forget. This regex cheat sheet gathers the character classes, anchors, quantifiers, groups, lookarounds, and flags you use most, each with a short meaning.
Keep it open while you write patterns. When you want to try a pattern against real text, use our free Regex Tester to see live matches as you type.
Character Classes
| Token | Matches / meaning |
|---|
. | Any character except a newline. |
\d | Any digit (0–9). |
\D | Any non-digit. |
\w | Any word character (letters, digits, underscore). |
\W | Any non-word character. |
\s | Any whitespace (space, tab, newline). |
\S | Any non-whitespace character. |
[abc] | Any one of a, b, or c. |
[^abc] | Any character except a, b, or c. |
[a-z] | Any character in the range a to z. |
Anchors & Boundaries
| Token | Matches / meaning |
|---|
^ | Start of the string (or line with the m flag). |
$ | End of the string (or line with the m flag). |
\b | A word boundary. |
\B | A non-word boundary. |
Quantifiers
| Token | Matches / meaning |
|---|
* | 0 or more of the preceding token. |
+ | 1 or more of the preceding token. |
? | 0 or 1 of the preceding token (optional). |
{n} | Exactly n of the preceding token. |
{n,} | n or more of the preceding token. |
{n,m} | Between n and m of the preceding token. |
*? | Lazy match — as few as possible. |
Groups & Alternation
| Token | Matches / meaning |
|---|
(abc) | Capturing group. |
(?:abc) | Non-capturing group. |
(?<name>abc) | Named capturing group. |
a|b | Match a or b (alternation). |
\1 | Backreference to the first capturing group. |
Lookaround
| Token | Matches / meaning |
|---|
(?=abc) | Positive lookahead — followed by abc. |
(?!abc) | Negative lookahead — not followed by abc. |
(?<=abc) | Positive lookbehind — preceded by abc. |
(?<!abc) | Negative lookbehind — not preceded by abc. |
Flags
| Token | Matches / meaning |
|---|
g | Global — find all matches, not just the first. |
i | Case-insensitive matching. |
m | Multiline — ^ and $ match line starts/ends. |
s | Dotall — . also matches newlines. |
u | Unicode mode. |
y | Sticky — match from lastIndex only. |
Regex Cheat Sheet FAQs
Where can I test a regular expression?
Try our free
Regex Tester, which highlights every match in your text in real time and supports all JavaScript flags.
What is the difference between greedy and lazy quantifiers?
Greedy quantifiers like * and + match as much as possible. Adding a ? (for example *?) makes them lazy, matching as little as possible.
What does \b mean in regex?
\b is a word boundary — a zero-width position between a word character and a non-word character. It is useful for matching whole words, like \bcat\b.
What is the difference between a capturing and non-capturing group?
A capturing group (abc) stores its match for later use or backreferences. A non-capturing group (?:abc) groups without storing, which is slightly faster when you don't need the captured value.
Does this regex syntax work in JavaScript?
Yes. This cheat sheet follows JavaScript (ECMAScript) regular expression syntax, and the same tokens work in most modern languages too.