Skip to content

Regex Cheat Sheet PDF: Download a Printable Quick Reference

A printable regex cheat sheet covering anchors, character classes, quantifiers and lookaheads — quick reference, free to use online or print.

Try it now: Regex Cheat Sheet Every token, quantifier, class, group and lookaround on one searchable page — each with a live example you can run, and the flavour differences called out.

Why a Page Beats a PDF Here

There's no downloadable file below, and that's deliberate. A regex cheat sheet PDF is frozen the moment it's exported — a browser or language adds a new construct (lookbehind support, named groups, the vflag) and every copy already on disk quietly goes stale. This page doesn't: it's updated in place, every row is text you can actually search with Ctrl-F or your browser's find bar (try searching this page for \bright now), and every pattern in every table is copy-pasteable straight into an editor or into GenKitLab's Regex Tester to confirm it does what the table says against your own text, in seconds. That combination — searchable, copyable, never out of date — is the actual job a PDF was standing in for. The tables below cover the JavaScript/PCRE-flavored syntax this site's regex tools support: character classes, anchors, quantifiers, groups, and lookarounds, one table per category, symbol first.

For the live, interactive version of this reference — every row rendered next to a working example you can edit — use GenKitLab's Regex Cheat Sheet. Everything on it runs entirely client-side; nothing you type is sent anywhere.

Character Classes

SymbolMeaningExample
\dA single digit, 0-9\d{3} matches 123
\DAny character that is not a digit\D+ matches abc in abc123
\wA word character: A-Z, a-z, 0-9, or _\w+ matches user_1
\WAny character that is not a word character\W matches @ in user@host
\sAny whitespace character — space, tab, newline, etc.a\sb matches a b
\SAny non-whitespace character\S+ matches hello in  hello 
.Any character except a line break, unless the s flag is seta.c matches abc, a c, a1c
[abc]Any one character from the listed set[aeiou] matches any single vowel
[^abc]Any one character not in the set — ^ negates only inside brackets[^0-9] matches any non-digit character
[a-z]A range — any character between the two endpoints, inclusive[a-zA-Z0-9] matches any single letter or digit

Anchors and Quantifiers

Anchors match a position, not a character; they never consume input.

SymbolMeaningExample
^Start of the string, or start of a line when the m flag is set^Hello matches only at the very beginning
$End of the string, or end of a line when the m flag is setend$ matches only at the very end
\bA word boundary — between a word character and a non-word character (or string edge)\bcat\b matches cat but not the cat in category
\BNot a word boundary\Bcat\B matches cat inside concatenate

Quantifiers repeat the token or group immediately before them.

SymbolMeaningExample
*Zero or more, greedyab*c matches ac, abc, abbc
+One or more, greedyab+c matches abc and abbc, not ac
?Zero or one — makes the preceding token optionalcolou?r matches color and colour
{n}Exactly n repetitions\d{4} matches exactly four digits, e.g. 2026
{n,}n or more repetitions\d{2,} matches two or more digits
{n,m}Between n and m repetitions, inclusive\d{2,4} matches two, three, or four digits
*? / +?Lazy versions of * and + — match as few repetitions as possible<.*?> on <b>bold</b> matches only <b>, where <.*> (greedy) would match the whole string

Groups, Backreferences and Lookarounds

SymbolMeaningExample
(...)A capturing group — its match is numbered and can be referenced or extracted(\d{3})-(\d{4}) captures the area code and the rest separately
(?:...)A non-capturing group — groups for quantifying or alternation without numbering the match(?:ab)+ matches ab, abab, etc., with no capture
(?<name>...)A named capturing group — matched text is available by name, not just by index(?<year>\d{4}) exposes the match as groups.year
\1A backreference to capturing group 1 — matches the exact same text again(\w)\1 matches any doubled letter, like the ll in hello
\k<name>A backreference to a named group(?<tag>\w+)=\k<tag> matches id=id but not id=name
(?=...)Lookahead — asserts what follows, without consuming it\d+(?=px) matches 16 in 16px, not the px
(?!...)Negative lookahead — asserts what does not follow\d+(?!px) matches 16 in 16em but not in 16px
(?<=...)Lookbehind — asserts what precedes, without consuming it(?<=\$)\d+ matches 20 in $20, not the $
(?<!...)Negative lookbehind — asserts what does not precede(?<!\$)\d+ matches 20 in £20 but not in $20

Verify Every Pattern Before You Trust It

A table is a reference, not proof — the fastest way to be sure a pattern from this page does what its “meaning” column claims is to run it against real text, not imagine it. Paste any symbol or example pattern above into GenKitLab's Regex Tester alongside a sample string and watch the highlighted matches update as you type, with named capture groups broken out and a replace preview available. For the full walkthrough of flags, matching modes, and how the replace syntax works, see the Regex Tester guide. And if a pattern needs to be built rather than looked up — from labelled blocks, or inferred from examples that should and shouldn't match — that's a separate job the cheat sheet links out to as well.

Frequently asked questions

Is there an actual regex cheat sheet PDF to download?

No, and that's intentional. A PDF is frozen the moment it's exported, while this page is a living reference: every table stays current, every row is searchable with your browser's own find function, and every example pattern is plain text you can copy straight into an editor or a tester — none of which a downloaded file gives you.

What's the difference between \d and [0-9]?

None in practice for standard digits — \d is shorthand for the character class [0-9]. Some regex flavors extend \d to match Unicode digits with the /u flag, but for everyday patterns the two are interchangeable.

When should I use a non-capturing group (?:...) instead of (...)?

Use (?:...) whenever you need to group tokens for a quantifier or alternation but don't need to extract or backreference that match. It keeps capture group numbering clean in a longer pattern where only some groups matter.

What's actually different between greedy and lazy quantifiers?

A greedy quantifier (*, +, {n,m}) matches as much as it can and backtracks only if the rest of the pattern fails; a lazy quantifier (*?, +?) matches as little as possible and expands only when it must. The difference shows up clearest around repeated delimiters, like <.*> matching an entire multi-tag string versus <.*?> matching just one tag.

Does JavaScript support lookbehind?

Yes, in every modern engine (V8, SpiderMonkey, JavaScriptCore) — both (?<=...) and (?<!...) work in current browsers and Node. It was the last of the four lookaround forms to land, which is exactly the kind of engine change that makes a static PDF go stale while a maintained web reference doesn't.

Does this regex reference run any of my text through a server?

No. Both this page and GenKitLab's Regex Tester and Regex Cheat Sheet tools run entirely client-side in your browser — nothing you type or paste is ever uploaded or logged.

Last updated