TL
Tool Lab
πŸ’°Donate
πŸ’°Donate

Regex Cheat Sheet

Complete regular expression syntax reference with patterns and examples.

Character Classes

.Any character except newline
\wWord character [a-zA-Z0-9_]
\WNon-word character
\dDigit [0-9]
\DNon-digit
\sWhitespace (space, tab, newline)
\SNon-whitespace
[abc]Character class β€” a, b, or c
[^abc]Negated class β€” not a, b, or c
[a-z]Range β€” any lowercase letter
[a-zA-Z0-9]Alphanumeric characters

Anchors

^Start of string (or line with multiline)
$End of string (or line with multiline)
\bWord boundary
\BNon-word boundary
\AStart of string (not multiline)
\ZEnd of string (not multiline)

Quantifiers

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

Groups & Alternation

(abc)Capture group
(?:abc)Non-capturing group
(?P<name>abc)Named capture group
a|bAlternation β€” a or b
(?=abc)Positive lookahead
(?!abc)Negative lookahead
(?<=abc)Positive lookbehind
(?<!abc)Negative lookbehind

Escapes & Special

\nNewline
\tTab
\rCarriage return
\0Null character
\uXXXXUnicode character (hex)
\.Literal dot (escaped)
\\Literal backslash

Flags

gGlobal β€” find all matches
iCase-insensitive
mMultiline β€” ^ and $ match line start/end
sDotall β€” . matches newline
uUnicode β€” treat pattern as Unicode
ySticky β€” match from lastIndex

Common Patterns

^[\w.-]+@[\w.-]+\.\w{2,}$Email address
https?://[\w./%-]+URL (basic)
^\d{1,3}(\.\d{1,3}){3}$IPv4 address
^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$Hex color
^\d{4}-\d{2}-\d{2}$ISO date (YYYY-MM-DD)
^[+]?[\d\s()-]{7,15}$Phone number (basic)
^(?=.*[A-Z])(?=.*\d).{8,}$Password: 8+ chars, 1 uppercase, 1 digit