← All cheatsheets

Text

Regex — the patterns you actually use

The regex syntax you actually use: anchors, character classes, quantifiers, groups and alternation, plus ready-made common patterns.

Anchors

^ — start of line

$ — end of line

\b — word boundary

Char classes

\d — digit

\w — word char (alnum + _)

\s — whitespace

. — any char

[abc] — a, b, or c

[^abc] — NOT a, b, or c

[a-z] — range

Quantifiers

* — 0 or more

+ — 1 or more

? — 0 or 1

{3} — exactly 3

{3,5} — 3 to 5

Groups + alternation

(abc) — group

(?:abc) — non-capturing group

abc|def — abc OR def

(\d+)-(\d+) — capture groups, refer with $1, $2

Common patterns

\d{3}-\d{4} — phone-ish

\b[A-Z]{2,}\b — all-caps acronyms

^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$ — email-ish (case-insensitive flag)