Regex Cheat Sheet Table

–type a pattern to test it live
TokenKindWhat it doesExample
.classAny one character except line breaks/a.y/ matches "any" in "many"
\dclassDigit, same as [0-9]/\d/ matches "2" in "B2"
\DclassAny non-digit/\D/ matches "B" in "B2"
\wclassWord character: [A-Za-z0-9_]/\w/ matches "I" in "I28"
\WclassNon-word character/\W/ matches "%" in "50%"
\sclassWhitespace: space, tab, newline/\s/ matches " " in "a b"
\SclassNon-whitespace/\S/ matches "a" in "a b"
[abc]classAny one of the enclosed characters/[abc]/ matches "b" in "brisket"
[^abc]classAnything except the enclosed characters/[^ab]/ matches "c" in "abc"
[a-z]classCharacter range/[a-z]{4}/ matches " qui" in "quiet"
^anchorStart of input (or line, with m flag)/^A/ matches "A" in "An apple"
$anchorEnd of input (or line, with m flag)/t$/ matches "t" in "eat"
\banchorWord boundary/\bno/ matches "no" at the start of "now"
\BanchorNot a word boundary/\Bb/ matches "b" inside "ab"
*quantifier0 or more, greedy/go*d/ matches "gd", "god", "good"
+quantifier1 or more, greedy/go+d/ matches "god", "good" but not "gd"
?quantifier0 or 1 of the previous item/colou?r/ matches "color" and "colour"
{n}quantifierExactly n times/o{2}/ matches "oo" in "moon"
{n,}quantifiern or more times/o{2,}/ matches "oooo" in "moooo"
{n,m}quantifierAt least n, at most m/o{1,2}/ matches "oo" in "moon"
*?quantifierLazy: stop at the first possible match/<.*?>/ matches "" in "bold"
x|ygroupAlternation: x or y/green|red/ matches "red" in "red fox"
(...)groupCapturing group, reusable as \1 or $1/(\d{4})-(\d{2})/ splits "2026-10" into two groups
(?:...)groupGroup without capturing/(?:ab)+/ matches "abab" as one match
(?<name>...)groupNamed capture group/(?\d{4})/ exposes match.groups.y
\1groupBackreference to group 1/(\w)\1/ matches "pp" in "apple"
(?=...)groupPositive lookahead: must follow, not consumed/\d+(?=px)/ matches "16" in "16px"
(?!...)groupNegative lookahead: must NOT follow/\d+(?!px)/ matches "3" in "3em"
\.escapeLiteral special character/\./ matches "." in "3.5"
gflagGlobal: find all matches, not just the first/a/g finds every "a"
iflagCase-insensitive/hello/i matches "HELLO"
mflag^ and $ match at every line boundarymulti-line anchors
sflagDot matches line breaks too (dotAll)/a.b/s spans newlines
uflagUnicode-aware: full code points, \p{...} classesemoji-safe matching
yflagSticky: match only at lastIndextokenizer loops
Token semantics follow MDN's regular expressions cheat sheet; the tester runs the exact JavaScript RegExp engine, so what matches here matches in the browser. Two classic traps the table disarms: quantifiers are greedy until you add ? (<.*> 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

  1. Type a pattern (with flags in the second box) and a test string; the chips load email, phone, and year patterns to start from.
  2. 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".
  3. 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>&lt;.*?&gt;</b> matches one tag, <b>&lt;.*&gt;</b> matches from the first &lt; to the final &gt; 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.

Related tools