Regex Cheatsheet

// Regex syntax quick reference

^
Start of string/line
^Hello
$
End of string/line
world$
\b
Word boundary
\bword\b
\B
Non-word boundary
\Bword\B
\A
Start of string (no multiline)
\AStart
\Z
End of string (no multiline)
End\Z
.
Any character except newline
a.b
\d
Digit [0-9]
\d{3}
\D
Non-digit [^0-9]
\D+
\w
Word character [a-zA-Z0-9_]
\w+
\W
Non-word character
\W
\s
Whitespace [ \t\n\r\f\v]
\s+
\S
Non-whitespace
\S+
[abc]
Character set (a, b, or c)
[aeiou]
[^abc]
Negated set (not a, b, or c)
[^0-9]
[a-z]
Character range
[a-zA-Z]
*
Zero or more
ab*c
+
One or more
ab+c
?
Zero or one (optional)
colou?r
{n}
Exactly n times
\d{4}
{n,}
n or more times
\w{3,}
{n,m}
Between n and m times
\d{2,4}
*?
Zero or more (lazy)
<.*?>
+?
One or more (lazy)
\w+?
??
Zero or one (lazy)
colou??r
*+
Zero or more (possessive)
\w*+
(abc)
Capturing group
(\d{3})-(\d{4})
(?:abc)
Non-capturing group
(?:https?://)
(?<name>abc)
Named capturing group
(?<year>\d{4})
\1
Backreference to group 1
(\w+)\s\1
a|b
Alternation (a or b)
cat|dog
(?=abc)
Positive lookahead
\d(?=px)
(?!abc)
Negative lookahead
\d(?!px)
(?<=abc)
Positive lookbehind
(?<=\$)\d+
(?<!abc)
Negative lookbehind
(?<!\$)\d+
g
Global - match all occurrences
/pattern/g
i
Case-insensitive matching
/hello/i
m
Multiline - ^ and $ match line boundaries
/^line/m
s
Dotall - . matches newlines
/a.b/s
u
Unicode - enable Unicode matching
/\p{L}/u
y
Sticky - match at lastIndex position
/pattern/y
Email
Basic email validation
[\w.-]+@[\w.-]+\.\w{2,}
URL
Basic URL matching
https?://[\w.-]+(?:/[\w.-]*)*
IPv4
IPv4 address
\b\d{1,3}(\.\d{1,3}){3}\b
Phone
US phone number
\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}
Date
Date (YYYY-MM-DD)
\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])
Hex Color
Hex color code
#(?:[0-9a-fA-F]{3}){1,2}\b

#About Regex Cheatsheet

Free online regex cheatsheet. Quick reference for regular expression syntax including anchors, quantifiers, character classes, groups, lookahead, and lookbehind. This tool runs entirely in your browser — your data is never sent to a server. Just paste your input, get instant results, and copy with one click. No sign-up or installation required.

#FAQ

What is a regular expression?
A regular expression (regex) is a sequence of characters that defines a search pattern. It is used for pattern matching in strings, commonly for validation, search-and-replace, and text parsing.
What is the difference between greedy and lazy quantifiers?
Greedy quantifiers (*, +, ?) match as much text as possible, while lazy quantifiers (*?, +?, ??) match as little as possible. For example, in the string "<b>bold</b>", the pattern <.*> matches the entire string (greedy) while <.*?> matches just <b> (lazy).
</> Embed this tool

Copy this code to embed the tool on your website. Adjust the height to fit your layout.

<iframe src="https://www.browserutils.dev/embed/regex-cheatsheet" width="100%" height="500" frameborder="0" title="Regex Cheatsheet"></iframe>

#Related