Regex Cheat Sheet
Every regex token you actually use, grouped by category, with a plain-English meaning and a real example — search to find the one you half-remember.
Character classes
.Any character except newline
a.c matches "abc", "a c"
\dA digit (0-9)
\d{3} matches "123"
\DAny non-digit
\D+ matches "abc" in "abc123"
\wA word character (letters, digits, underscore)
\w+ matches "hello_1"
\WAny non-word character
\W matches " ", "-", "!"
\sAny whitespace (space, tab, newline)
a\sb matches "a b"
\SAny non-whitespace character
\S+ matches "hello"
[abc]Any one of the listed characters
[aeiou] matches any vowel
[^abc]Any character NOT listed
[^0-9] matches any non-digit
[a-z]Any character in the range
[a-zA-Z] matches any letter
Quantifiers
*Zero or more of the preceding token
ab*c matches "ac", "abc", "abbbc"
+One or more of the preceding token
ab+c matches "abc" but not "ac"
?Zero or one of the preceding token (optional)
colou?r matches "color" and "colour"
{n}Exactly n occurrences
\d{4} matches a 4-digit number
{n,}n or more occurrences
\d{2,} matches 2+ digits
{n,m}Between n and m occurrences
\d{2,4} matches 2 to 4 digits
*? +? ??Lazy (non-greedy) versions — match as little as possible
<.+?> on "<a><b>" matches "<a>" only
Anchors & boundaries
^Start of the string (or line, with the m flag)
^Hello matches "Hello world" only at the start
$End of the string (or line, with the m flag)
world$ matches "hello world" only at the end
\bA word boundary
\bcat\b matches "cat" but not "category"
\BNOT a word boundary
\Bcat matches "concat" but not "cat"
Groups & alternation
(...)A capturing group — matched text is extractable
(\d{4})-(\d{2}) captures year and month
(?:...)A non-capturing group — groups without capturing
(?:abc)+ groups "abc" for repetition only
(?<name>...)A named capturing group
(?<year>\d{4}) captures as "year"
|Alternation — matches either side
cat|dog matches "cat" or "dog"
\1A backreference to capture group 1
(\w)\1 matches any doubled letter, e.g. "ss"
Lookaround
(?=...)Lookahead — matches if followed by this pattern (not included in the match)
\d+(?=px) matches "10" in "10px"
(?!...)Negative lookahead — matches if NOT followed by this pattern
\d+(?!px) matches "10" in "10em" but not in "10px"
(?<=...)Lookbehind — matches if preceded by this pattern
(?<=\$)\d+ matches "10" in "$10"
(?<!...)Negative lookbehind — matches if NOT preceded by this pattern
(?<!\$)\d+ matches "10" in "10 items" but not "$10"
Flags
gGlobal — find all matches, not just the first
iCase-insensitive matching
mMultiline — ^ and $ match the start/end of each line
sDot-all — . also matches newlines
uUnicode — enables full Unicode pattern support
ySticky — matches only starting at lastIndex
About the Regex Cheat Sheet
Regex syntax is dense by design — a handful of symbols cover an enormous range of matching logic, which is exactly why it's so easy to half-remember. This reference groups tokens the way you actually think about them while writing a pattern: what am I matching, how many of it, and where.
Most of what's here is shared across regex engines (JavaScript, Python, PCRE), but a few features — like lookbehind and named capture groups — have historically had inconsistent support, so it's worth confirming a given token works in your specific engine, especially for regex targeting older environments.
How to use it
- 1Search for what you're trying to do, e.g. "digit" or "lookahead".
- 2Read the symbol, its meaning, and an example.
- 3Jump to the Regex Tester to try it against real text.
Features
- Character classes, quantifiers, anchors, groups and lookaround
- Every entry paired with a real example, not just the symbol
- Instant search across symbols and descriptions
- One click through to the Regex Tester to try any pattern live
Frequently asked questions
What is the difference between * and +?
* matches zero or more of the preceding token (so it can match nothing); + requires at least one occurrence.
What does (?:...) mean?
It's a non-capturing group — it groups a pattern for alternation or quantifying without creating a numbered capture group in the results, useful when you need grouping but don't need to extract that part.
What is the difference between lookahead and lookbehind?
Both check for a pattern without including it in the match. Lookahead (?=...) checks what follows the current position; lookbehind (?<=...) checks what precedes it.
Where can I test a pattern from here?
Every entry links to the Regex Tester, where you can try it against real text with live match highlighting.