Skip to content

Regex Cheatsheet

Embed

Paste this where you want Regex Cheatsheet on your site. Adjust the height to fit.

<iframe src="https://www.browserutils.dev/embed/regex-cheatsheet/" width="100%" height="500" frameborder="0" loading="lazy" title="Regex Cheatsheet"></iframe>
<p style="font-size:12px;margin:4px 0 0"><a href="https://www.browserutils.dev/tools/regex-cheatsheet/">Regex Cheatsheet</a> by BrowserUtils</p>

Regex syntax quick reference.Runs in this tab.

^
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

Next step

About Regex Cheatsheet

Free online regex cheatsheet. Quick reference for regular expression syntax including anchors, quantifiers, character classes, groups, lookahead, and lookbehind. It runs in your browser. Nothing is sent to a server.

Questions

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).
How do I write a regex to validate an email address?
A basic pattern is ^[\w.-]+@[\w.-]+\.[a-zA-Z]{2,}$. However, fully RFC-compliant email validation with regex is extremely complex. For production use, combine a simple regex with server-side verification.
Is regex syntax the same across all programming languages?
The core syntax (character classes, quantifiers, anchors) is similar across most languages, but advanced features differ. For example, lookbehind support, named groups, and Unicode property escapes vary between JavaScript, Python, PCRE, and others.
What are lookahead and lookbehind in regex?
Lookahead (?=...) and lookbehind (?<=...) are zero-width assertions that match a position based on what comes after or before it, without including those characters in the match. They are useful for conditional matching without consuming text.

More in Developer Reference

All 18 developer reference