🔍
Regex Patterns Cheatsheet
Common regex patterns for email, URL, phone, UUID, date validation and more.
Common Validation Patterns
| Pattern Name | Regex | Matches |
|---|---|---|
| ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$ | user@domain.com | |
| URL | ^https?://[\S]+$ | https://example.com/path?q=1 |
| IPv4 | ^(\d{1,3}\.){3}\d{1,3}$ | 192.168.1.1 |
| IPv6 (simple) | ^([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$ | 2001:db8::1 |
| UUID | ^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$ | 550e8400-e29b-41d4-a716-446655440000 |
| ISO Date | ^\d{4}-\d{2}-\d{2}$ | 2026-06-16 |
| Time (HH:MM) | ^([01]\d|2[0-3]):[0-5]\d$ | 14:30 |
| Phone (intl) | ^\+?[1-9]\d{1,14}$ | +1234567890 |
| Hex color | ^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$ | #3A5FCD or #F0F |
| Slug | ^[a-z0-9]+(?:-[a-z0-9]+)*$ | my-blog-post |
| Credit card (basic) | ^[0-9]{13,19}$ | 4111111111111111 |
| JWT | ^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$ | hdr.payload.sig |
Regex Character Classes
| Class | Equivalent | Matches |
|---|---|---|
| \d | [0-9] | Any digit |
| \D | [^0-9] | Any non-digit |
| \w | [a-zA-Z0-9_] | Word character |
| \W | [^a-zA-Z0-9_] | Non-word character |
| \s | [ \t\n\r\f] | Whitespace |
| \S | [^ \t\n\r\f] | Non-whitespace |
| . | (any) | Any character except newline |
| ^ | Start of string (or line with m flag) | |
| $ | End of string (or line with m flag) |
Quantifiers
| Quantifier | Meaning |
|---|---|
| * | 0 or more (greedy) |
| + | 1 or more (greedy) |
| ? | 0 or 1 (greedy) |
| {n} | Exactly n |
| {n,} | n or more |
| {n,m} | Between n and m |
| *? | 0 or more (lazy) |
| +? | 1 or more (lazy) |