Regex Cheat Sheet
A filterable reference table of 30 core regex tokens — character classes, quantifiers, groups, lookaheads and anchors — each with a worked example.
Worked examples
- Full reference, no filter
The default view: every token in the reference, for scanning or Ctrl+F-ing the whole list at once.
- Filtered to grouping and backreference syntax
Typing "group" narrows the table to capturing, non-capturing, named-group and backreference syntax — useful when you specifically forgot the named-group syntax.
- A filter with no matches
A filter that matches nothing returns an empty table rather than falling back to the full list, so it's clear the term wasn't found.
What this tool does
This is a filterable reference table of 30 core regex tokens — character classes, anchors, quantifiers, groups and lookaround assertions — each paired with a plain description and a worked example showing what it matches. Type a keyword to narrow the table instead of scrolling through the full syntax reference.
When you need it
- Looking up the exact syntax for something you use rarely enough to forget — named capture groups, lookbehind, the difference between
\band\B— without leaving the page to search elsewhere. - Teaching or learning regex, where seeing a token next to a concrete example clarifies it faster than a syntax definition alone.
- Double-checking whether a token means what you think it means before using it in a pattern that will run against production data.
- Quickly scanning quantifier syntax (
{n},{n,},{n,m}) when you always mix up which one allows an unbounded upper limit.
How the filter works
Typing into the filter box narrows the table to rows whose token, description or example contains your search term, checked case-insensitively. Searching "group" surfaces capturing groups, non-capturing groups, named groups and backreferences together, since they're conceptually related even though their syntax differs. Searching "lookahead" or "lookbehind" isolates the positive and negative assertion of that kind, and searching "look" shows all four. An empty filter shows the complete table.
What's covered
The table spans character classes (\d, \w, \s and their negations), the wildcard ., anchors (^, $, word boundaries), quantifiers including the lazy *? modifier, character class syntax ([abc], [^abc], ranges like [a-z]), all four grouping forms, alternation with |, and all four lookaround assertions (positive and negative lookahead and lookbehind). It's a curated set focused on the tokens people actually look up most often, not an exhaustive enumeration of every regex feature in every engine.
A note on portability
Everything in this table is standard JavaScript regex syntax, and most of it is shared by Python, PCRE and Java. Two features are worth double-checking if you're writing for a specific language: lookbehind assertions ((?<=...), (?<!...)) aren't supported in some older regex engines, and named capture groups are written (?<name>...) in JavaScript, Java and .NET but (?P<name>...) in Python. If a pattern using either of these doesn't behave as expected outside JavaScript, that's the first place to look.
Try it live
Once you've found the token you need, paste a pattern using it into the regex tester tool to run it against real sample text and see the actual matches, rather than reasoning about it from the description alone.
Frequently asked questions
- Is this specific to one programming language?
- It covers the core syntax shared by JavaScript, Python, PCRE and most other modern regex engines. A few tokens differ: named groups are (?P<name>...) in Python, and lookbehind is missing or restricted in some engines — check your language's docs if a pattern doesn't behave as expected.
- How does the filter work?
- Type any keyword and the table narrows to rows whose token, description or example contains it — for example "lookahead" shows just the two lookahead rows.
- Where can I try a token against real text?
- Use the regex tester tool to run any of these tokens against sample text and see the matches directly.
- Why isn't there a row for flags like g or i?
- Flags aren't part of the pattern syntax itself — they're engine options set alongside the pattern — so they're covered in the regex tester's own documentation instead.