Skip to content
ZeroServer.tools

Regex Cheat Sheet

Complete regular expression reference — anchors, quantifiers, groups, lookaheads, and flags.

Anchors

PatternDescription
^Start of string (or line in multiline mode)
$End of string (or line in multiline mode)
\bWord boundary
\BNon-word boundary
\AStart of string (no multiline)
\ZEnd of string (no multiline)

Character Classes

PatternDescription
.Any character except newline
\dDigit [0–9]
\DNon-digit
\wWord character [A-Za-z0-9_]
\WNon-word character
\sWhitespace (space, tab, newline)
\SNon-whitespace
[abc]Character set — any of a, b, or c
[^abc]Negated character set
[a-z]Character range
[a-zA-Z]Case-insensitive range

Quantifiers

PatternDescription
*Zero or more (greedy)
+One or more (greedy)
?Zero or one (optional)
{n}Exactly n times
{n,}n or more times
{n,m}Between n and m times
*?Zero or more (lazy)
+?One or more (lazy)
??Zero or one (lazy)

Groups & Alternation

PatternDescription
(abc)Capture group — captures match
(?:abc)Non-capturing group
(?P<name>abc)Named capture group
a|bAlternation — a or b
\1Backreference to group 1

Lookahead & Lookbehind

PatternDescription
(?=abc)Positive lookahead — followed by
(?!abc)Negative lookahead — not followed by
(?<=abc)Positive lookbehind — preceded by
(?<!abc)Negative lookbehind — not preceded by

Flags

PatternDescription
gGlobal — find all matches (not just first)
iCase-insensitive match
mMultiline — ^ and $ match line boundaries
sDotall — . matches newline too
uUnicode — enables Unicode escapes
ySticky — match at lastIndex only
dIndices — report match indices

Special & Escape

PatternDescription
\nNewline
\tTab
\rCarriage return
\uXXXXUnicode code point
\xHHHex code point
\0Null character
\\Literal backslash

Using this regex cheat sheet

Regular expressions are patterns used to match character combinations in strings. Most engines support PCRE-style syntax: anchors, character classes, quantifiers, groups, and lookaheads. JavaScript adds the g, i, m,s, u, and y flags via the RegExp object.

To test a regex against sample text, use the Regex Tester. To visualize how a pattern matches, try the Regex Visualizer. To escape special characters, see Regex Escape Tool.

Private & free — this tool runs entirely in your browser.

Recommended: IndieKit Ship your Next.js startup in days.affiliate

Related Developer Utilities tools