Reference · Regex · Cheatsheet
JavaScript Regex Cheatsheet
The patterns you reach for most — character classes, anchors, flags, lookarounds, and common recipes. Keep this tab open next to your editor.
Core Syntax
Character Classes
.any character except newline (or any withsflag)\ddigit,\Dnon-digit\wword character,\Wnon-word\swhitespace,\Snon-whitespace[abc]any of a, b, c ·[^abc]none of them ·[a-z]range
Quantifiers
*zero or more ·+one or more ·?optional{n}exactly n ·{n,}n or more ·{n,m}between n and m- Add
?for lazy matching:.*?smallest match
Anchors
^start of input (or line withmflag)$end of input (or line withmflag)\bword boundary ·\Bnon-boundary
Groups
(abc)capturing group(?:abc)non-capturing group(?<name>abc)named group\1backreference ·$1,$<name>in replacement
Lookarounds
(?=abc)positive lookahead(?!abc)negative lookahead(?<=abc)positive lookbehind(?<!abc)negative lookbehind
Flags
gglobal ·icase-insensitive ·mmultilinesdot matches newline ·uUnicode ·ysticky
Common Recipes
Email (loose)
/^[^\s@]+@[^\s@]+\.[^\s@]+$/UUID v4
/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iISO date (YYYY-MM-DD)
/^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$/Slug (URL fragment)
/^[a-z0-9]+(?:-[a-z0-9]+)*$/HEX color
/^#(?:[0-9a-f]{3}){1,2}$/iTry It
Test any of these patterns in our free Regex Tester with live match highlighting and capture-group inspection.
Fail fast
Anchor patterns with ^ and $ when you need a full-string match.
Name your groups
Named groups beat $1/$2 for anything you'll re-read later.
Validate at the edge
Regex is for shape, not business rules — parse, don't validate.