A searchable cheat sheet for regular expressions — character classes, anchors, quantifiers, groups, alternation, lookaround, and flags — each with a plain-English meaning. It is handy when you are mid-pattern and just need to recall what \b, *?, or (?<=...) does without leaving your work.
How it works
The reference groups every common regex token by category — character classes, anchors, quantifiers, groups, lookaround, and flags — and shows a concise description of what each matches. Type a token or keyword such as digit, lookahead, or quantifier into the search box and the list filters instantly to the matching entries. It is purely a static lookup that follows the conventions shared by JavaScript and PCRE, so nothing is executed against your data.
Token quick-reference
Searching for digit surfaces the character-class tokens. A few of the most-used tokens:
| Token | Matches |
|---|---|
. | Any character except newline |
\d / \D | A digit / a non-digit |
\w / \W | A word character / non-word character |
\s / \S | Whitespace / non-whitespace |
^ / $ | Start / end of string (or line with m) |
\b | Word boundary |
* + ? | 0+, 1+, 0 or 1 (add ? for lazy) |
{n,m} | Between n and m repetitions |
(?=...) / (?!...) | Positive / negative lookahead |
(?<=...) / (?<!...) | Positive / negative lookbehind |
Common patterns explained
Greedy vs lazy quantifiers — this is where most regex bugs hide. ".*" is greedy: given the string "foo" and "bar", it matches the entire span from the first " to the last ", consuming both quoted strings. Switch to ".*?" and the lazy ? makes it stop at the first closing quote, matching only "foo". When you are extracting delimited values, lazy is almost always what you want.
Word boundaries — \b is a zero-width assertion that matches the transition between a word character (\w) and a non-word character. It lets you find cat as a whole word without accidentally matching category or concatenate. Because \b matches a position rather than a character, it never appears in the captured text.
Flags change how the whole pattern behaves. The most important ones:
| Flag | Effect |
|---|---|
g | Find all matches, not just the first |
i | Case-insensitive matching |
m | ^ and $ match line boundaries, not just string boundaries |
s | Dotall — . matches newlines too |
u | Enable full Unicode support |
Lookaround quick guide
Lookahead and lookbehind let you assert what surrounds a match without consuming it — they are invisible fence-posts, not actual characters in the match.
(?=price)— positive lookahead: match only if what follows isprice(?!draft)— negative lookahead: match only if what follows is notdraft(?<=\$)— positive lookbehind: match only if$immediately precedes(?<!un)— negative lookbehind: match only ifundoes not immediately precede
A typical use: \d+(?= items?) captures a count only when the word “item” or “items” follows it, without including that word in the match.
When regex is the wrong tool
Regex is excellent for pattern matching in strings, but it is the wrong tool for deeply nested structures. Parsing HTML, XML or JSON with a single regex is fragile — use a proper parser for those. Similarly, regex has no memory of what it matched earlier in the same string unless you use backreferences (\1, \2), which become hard to read fast. For complex grammars, consider a parser combinator library instead.
Everything runs in your browser; nothing is uploaded.