Regex Cheatsheet

Anchors

^Start of string/line
$End of string/line
\bWord boundary
\BNon-boundary

Character classes

[abc]Any of a, b, c
[^abc]Anything but a, b, c
[a-z]Range lowercase a–z
[0-9]Digit 0–9
.Any except newline

Predefined classes

\dDigit (0-9)
\DNon-digit
\wWord char [A-Za-z0-9_]
\WNon-word
\sWhitespace
\SNon-whitespace

Quantifiers

*0 or more
+1 or more
?0 or 1 (optional)
{n}Exactly n
{n,}n or more
{n,m}Between n and m
?? *? +?Lazy quantifiers

Groups & references

(abc)Capturing group
(?:abc)Non-capturing group
(?<name>abc)Named group
\1, \2Backreference to group 1, 2
\k<name>Named backreference

Lookaround

(?=abc)Positive lookahead
(?!abc)Negative lookahead
(?<=abc)Positive lookbehind
(?<!abc)Negative lookbehind

Alternation

a|bMatch a OR b

Escapes

\\Literal backslash
\.Literal period
\nNewline
\tTab
\xFFHex char
\u00FFUnicode char

Flags (JS)

gGlobal — all matches
iCase-insensitive
mMultiline (^ and $ per line)
sDotall (. matches newline)
uUnicode
ySticky

About this tool

Regex Cheatsheet is a single-purpose utility on instant.tw, a free toolbox of calculators, converters, generators, and quick lookups. Everything works in your browser — nothing is uploaded, nothing is stored on a server unless explicitly noted.

Category: Developer Tools — Advanced. Browse more Developer Tools — Advanced tools.