Advertisement
← All Cheat Sheets

Regex Patterns Cheat Sheet

Essential Regular Expression patterns and syntax for developers

Character Classes

\dAny digit (0-9)
\wAny word character (a-z, A-Z, 0-9, _)
\sAny whitespace (space, tab, newline)
.Any character except newline
[abc]Any character in the set (a, b, or c)
[^abc]Any character NOT in the set

Quantifiers

*0 or more occurrences
+1 or more occurrences
?0 or 1 occurrence
{n}Exactly n occurrences
{n,}n or more occurrences
{n,m}Between n and m occurrences

Anchors & Boundaries

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

Groups & Lookaround

(abc)Capture group
(?:abc)Non-capturing group
(?=abc)Positive lookahead
(?!abc)Negative lookahead

Common Patterns

^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$Email Address
^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$URL
^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$Hex Color Code
^\d{4}-\d{2}-\d{2}$Date (YYYY-MM-DD)
Advertisement