Regex Cheat Sheet Table
| Token | Kind | What it does | Example |
|---|---|---|---|
| . | class | Any one character except line breaks | /a.y/ matches "any" in "many" |
| \d | class | Digit, same as [0-9] | /\d/ matches "2" in "B2" |
| \D | class | Any non-digit | /\D/ matches "B" in "B2" |
| \w | class | Word character: [A-Za-z0-9_] | /\w/ matches "I" in "I28" |
| \W | class | Non-word character | /\W/ matches "%" in "50%" |
| \s | class | Whitespace: space, tab, newline | /\s/ matches " " in "a b" |
| \S | class | Non-whitespace | /\S/ matches "a" in "a b" |
| [abc] | class | Any one of the enclosed characters | /[abc]/ matches "b" in "brisket" |
| [^abc] | class | Anything except the enclosed characters | /[^ab]/ matches "c" in "abc" |
| [a-z] | class | Character range | /[a-z]{4}/ matches " qui" in "quiet" |
| ^ | anchor | Start of input (or line, with m flag) | /^A/ matches "A" in "An apple" |
| $ | anchor | End of input (or line, with m flag) | /t$/ matches "t" in "eat" |
| \b | anchor | Word boundary | /\bno/ matches "no" at the start of "now" |
| \B | anchor | Not a word boundary | /\Bb/ matches "b" inside "ab" |
| * | quantifier | 0 or more, greedy | /go*d/ matches "gd", "god", "good" |
| + | quantifier | 1 or more, greedy | /go+d/ matches "god", "good" but not "gd" |
| ? | quantifier | 0 or 1 of the previous item | /colou?r/ matches "color" and "colour" |
| {n} | quantifier | Exactly n times | /o{2}/ matches "oo" in "moon" |
| {n,} | quantifier | n or more times | /o{2,}/ matches "oooo" in "moooo" |
| {n,m} | quantifier | At least n, at most m | /o{1,2}/ matches "oo" in "moon" |
| *? | quantifier | Lazy: stop at the first possible match | /<.*?>/ matches "" in "bold" |
| x|y | group | Alternation: x or y | /green|red/ matches "red" in "red fox" |
| (...) | group | Capturing group, reusable as \1 or $1 | /(\d{4})-(\d{2})/ splits "2026-10" into two groups |
| (?:...) | group | Group without capturing | /(?:ab)+/ matches "abab" as one match |
| (?<name>...) | group | Named capture group | /(? |
| \1 | group | Backreference to group 1 | /(\w)\1/ matches "pp" in "apple" |
| (?=...) | group | Positive lookahead: must follow, not consumed | /\d+(?=px)/ matches "16" in "16px" |
| (?!...) | group | Negative lookahead: must NOT follow | /\d+(?!px)/ matches "3" in "3em" |
| \. | escape | Literal special character | /\./ matches "." in "3.5" |
| g | flag | Global: find all matches, not just the first | /a/g finds every "a" |
| i | flag | Case-insensitive | /hello/i matches "HELLO" |
| m | flag | ^ and $ match at every line boundary | multi-line anchors |
| s | flag | Dot matches line breaks too (dotAll) | /a.b/s spans newlines |
| u | flag | Unicode-aware: full code points, \p{...} classes | emoji-safe matching |
| y | flag | Sticky: match only at lastIndex | tokenizer loops |
<.*> swallows a whole tag pair, <.*?> stops at the first >), and a literal dot needs escaping - unescaped . happily matches any character. Bottom line: most real-world patterns are three moves - a character class, a quantifier, and an anchor - and the tester above proves all three before you paste them into production code. Sibling references: ASCII table, Unicode character inspector, MIME types table.Regular expressions compress "find text shaped like this" into a few characters - and forget one backslash and they match nothing, or everything. This table lists every JavaScript regex token with what it does and a worked example, and the tester above runs your pattern on the actual browser RegExp engine, so a green result here is a green result in production.
The semantics follow MDN’s cheat sheet; the difference is the execution layer - type a pattern, flags, and a test string, and you see the exact matches, or the exact error, immediately.
How to use
- Type a pattern (with flags in the second box) and a test string; the chips load email, phone, and year patterns to start from.
- Read the table when a pattern misbehaves: the quantifier rows explain greedy vs lazy, the anchor rows explain why \bno matches "now" but not "eno".
- Share or bookmark the page - the pattern and flags travel in the URL so a teammate opens the same test.
Frequently asked questions
Why does my pattern match too much?
Quantifiers are greedy: <b>.*</b> grabs everything up to the last possible match. The lazy forms *?, +? and ?? stop at the first - <b><.*?></b> matches one tag, <b><.*></b> matches from the first < to the final > of the string.
Why do I need a backslash before a dot?
In regex, <b>.</b> means "any character", so 3.5 could match 3x5. <b>\.</b> escapes it to a literal dot. The same applies to other specials: \(, \[, \\ - when a pattern "matches nothing", an unescaped special is the usual suspect.
What is the difference between (?:...) and (...) and (?=...)?
(...) captures for reuse (\1 or $1), (?:...) groups without capturing - cleaner when you only need grouping, and (?=...) is a lookahead: it checks what follows without consuming it, so overlapping matches stay possible - /\d+(?=px)/ finds the number in "16px" but not the "px".
What does the s flag change?
By default the dot matches everything except line breaks. With s (dotAll), it crosses lines too - the difference between matching a single-line value and a multiline block with one pattern.