Regex Cheatsheet
Searchable regex reference. Type a character or term to filter the table. Covers character classes, quantifiers, anchors, groups, lookarounds, flags, and a copy-paste list of common patterns (email, URL, IP, date, etc.).
How to use the Regex Cheatsheet
Type any term — "digit", "lookahead", "email", "word boundary" — to filter. Each row has the syntax, what it does, and an example.
The building blocks every regex is made of
However complex a pattern looks, it is assembled from a small set of pieces: literals (plain characters), character classes ([...], \d, \w), quantifiers (*, +, {2,5}), anchors (^, $, \b), groups ((...)), alternation (a|b), lookarounds ((?=...)), and flags (g, i, m).
Learn those eight categories and almost any regex becomes readable — you stop seeing line noise and start seeing structure. This cheatsheet is searchable so you can jump straight to the one piece you forgot, with a worked example for each rather than just a symbol and a name.
Common use cases
- Quick reference while coding — look up the syntax you use once a month, like lazy quantifiers or backreferences.
- Learning regex — work through the categories in order to build a real mental model.
- Interview prep — refresh the syntax that comes up in screening questions.
- Reading someone else's pattern — decode an unfamiliar regex one construct at a time.
- Settling a doubt — confirm whether
{2,}means "two or more" before you ship it.
Frequently asked questions
What is the difference between greedy and lazy quantifiers?
.*) grab as much as possible and then give back; lazy ones (.*?) take as little as possible and then expand. Lazy matching is what you want when capturing the shortest span between two delimiters.When should I use a non-capturing group <code>(?:...)</code>?
What does a backreference like <code>\1</code> do?
(\w)\1 matches a doubled character — the ss in pass, for example — because \1 must equal whatever group 1 matched.What changes when I add the global flag?
g a search returns only the first match; with it you iterate over every match. In JavaScript the g flag also makes RegExp.test() stateful via lastIndex, which surprises people.