A regex cheatsheet (regular expression reference) gives you instant access to the syntax patterns you need without digging through documentation. Use the sections below to look up character classes, quantifiers, anchors, groups, and lookaheads — then test your pattern live in the interactive tester at the top.

Live Regex Tester

/ / gi

Common Presets

Character Classes

PatternDescriptionExample match
Any character except newline a.c → "abc", "aXc"
Word character [a-zA-Z0-9_] \w+ → "hello", "foo_1"
Non-word character \W → " ", "!", "@"
Digit [0-9] \d+ → "42", "2024"
Non-digit \D → "a", " ", "-"
Whitespace (space, tab, newline) \s+ → "   ", "\t"
Non-whitespace \S+ → "hello", "42"
Character set — matches a, b, or c [aeiou] → vowels
Negated set — not a, b, or c [^0-9] → non-digits
Range — lowercase a to z [a-zA-Z] → any letter

Quantifiers

PatternDescriptionExample match
0 or more (greedy) ab* → "a", "ab", "abbb"
1 or more (greedy) ab+ → "ab", "abbb"
0 or 1 — optional colou?r → "color", "colour"
Exactly 3 times \d{3} → "555"
Between 2 and 5 times \w{2,5} → "ab", "hello"
2 or more times \d{2,} → "12", "2024"
0 or more (lazy) a.*?b → shortest "aXb"
1 or more (lazy) a.+?b → shortest match
0 or more (possessive) No backtracking (JS: not supported)

Anchors

PatternDescriptionExample match
Start of string (or line with m flag) ^\d → "4" in "42 apples"
End of string (or line with m flag) \d$ → "9" in "I have 9"
Word boundary \bcat\b → "cat" not "catch"
Non-word boundary \Bcat\B → "cat" in "concatenate"

Groups & Alternation

PatternDescriptionExample match
Capturing group (\d+) captures digits
Non-capturing group (?:ab)+ → "ababab"
Named capturing group (?<year>\d{4})
Back-reference to group 1 (\w+) \1 → "the the"
Alternation — matches a or b cat|dog → "cat", "dog"

Lookahead & Lookbehind

PatternDescriptionExample match
Positive lookahead — followed by \d+(?= px) → "12" in "12 px"
Negative lookahead — not followed by \d+(?! px) → digits without px
Positive lookbehind — preceded by (?<=\$)\d+ → "42" in "$42"
Negative lookbehind — not preceded by (?<!\$)\d+ → "42" not in "$42"

Flags

FlagDescriptionUsage
Global — find all matches /\d+/g
Case-insensitive /hello/i → "Hello", "HELLO"
Multiline — ^ and $ match line edges /^\w+/gm
DotAll — . matches newline too /a.b/s → "a\nb"
Unicode — enables full Unicode support /\p{Emoji}/u
Sticky — match at lastIndex position /\d+/y
Indices — report start/end of matches /\d+/d (ES2022)

Escape Sequences & Special Characters

SequenceDescriptionNotes
Newline Use s flag for . to match \n
Tab Horizontal tab character
Carriage return Windows line endings use \r\n
Literal dot (escaped metachar) Escape: . * + ? ^ $ { } [ ] | ( ) \
Unicode code point \u0041 → "A"
Copied to clipboard!