Back to Guides

Regex Cheat Sheet: The Patterns You Actually Use

Regex references online tend to list every arcane feature. This one lists the parts you actually reach for: extracting things, redacting things, splitting things, validating things.

Last reviewed: 2026-08-03

Character classes

Match a set of characters at one position.

\d        one digit (0-9)
\D        one non-digit
\w        one word char [A-Za-z0-9_]
\W        one non-word char
\s        one whitespace char
.         any char except newline
[abc]     literally a, b, or c
[^abc]    anything except a, b, or c
[a-z]     range a through z

Quantifiers

Repeat the previous atom.

*         zero or more
+         one or more
?         zero or one
{3}       exactly 3
{3,}      3 or more
{3,7}     between 3 and 7

Anchors and boundaries

^         start of string
$         end of string
\b        word boundary
\B        NOT a word boundary

Groups and captures

(abc)             capturing group
(?:abc)           non-capturing group
(?<name>abc)      named capture
(?=abc)           positive lookahead
(?!abc)           negative lookahead

Flags

g   global - return ALL matches
i   case-insensitive
m   multiline
s   dotall - . matches newlines
u   unicode support

Patterns you'll actually use

// Extract URLs
https?://[^\s"'<>]+

// Loose email
a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}

// ISO date
(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})