often.cloud
source
← all tools

Regex cheat sheet

Web

Searchable reference for JavaScript regular expressions.

Character classes

.Any character except newline
\w \d \sWord, digit, whitespace
\W \D \SNOT word, digit, whitespace
[abc]Any of a, b, c
[a-z]Range a to z
[^abc]NOT a, b, or c
\bWord boundary

Quantifiers

a*0 or more a
a+1 or more a
a?0 or 1 a
a{3}Exactly 3 a
a{2,4}2 to 4 a
a{3,}3 or more a
a*?Non-greedy (lazy)

Anchors

^Start of string / line
$End of string / line
\A \ZStart / end of string (not multiline)

Groups & alternation

(abc)Capture group
(?:abc)Non-capturing group
(?<name>abc)Named capture
a|ba OR b
\1Backreference to group 1
(?=abc)Positive lookahead
(?!abc)Negative lookahead
(?<=abc)Positive lookbehind
(?<!abc)Negative lookbehind

Flags

gGlobal — find all matches
iCase-insensitive
mMultiline — ^ and $ match line breaks
s. matches newlines (dotall)
uUnicode
ySticky — match at lastIndex only

Common patterns

^[\w.+-]+@[\w-]+\.[\w.-]+$Email (basic)
^https?://[^\s]+$URL
^\d{4}-\d{2}-\d{2}$Date YYYY-MM-DD
^\+?[1-9]\d{1,14}$Phone (E.164)
\b[0-9a-f]{6,8}\bHex color (6 or 8)
^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$UUID