developer5 sections · 45 items
Regular Expression Patterns Cheat Sheet
Quick reference for regex syntax, character classes, quantifiers, anchors, groups, and common validation patterns. Essential for developers.
Character Classes
| Item | Value |
|---|---|
| . | Any character except newline |
| \d | Any digit (0-9) |
| \D | Any non-digit |
| \w | Word char (a-z, A-Z, 0-9, _) |
| \W | Any non-word character |
| \s | Whitespace (space, tab, newline) |
| \S | Any non-whitespace |
| [abc] | Any of a, b, or c |
| [^abc] | Not a, b, or c |
| [a-z] | Any lowercase letter |
Quantifiers
| Item | Value |
|---|---|
| * | 0 or more |
| + | 1 or more |
| ? | 0 or 1 (optional) |
| {n} | Exactly n times |
| {n,} | n or more times |
| {n,m} | Between n and m times |
| *? | 0 or more (lazy) |
| +? | 1 or more (lazy) |
| ?? | 0 or 1 (lazy) |
Anchors & Boundaries
| Item | Value |
|---|---|
| ^ | Start of string (or line with m flag) |
| $ | End of string (or line with m flag) |
| \b | Word boundary |
| \B | Not a word boundary |
| (?=...) | Positive lookahead |
| (?!...) | Negative lookahead |
| (?<=...) | Positive lookbehind |
| (?<!...) | Negative lookbehind |
Groups & Flags
| Item | Value |
|---|---|
| (abc) | Capturing group |
| (?:abc) | Non-capturing group |
| (?<name>abc) | Named capturing group |
| a|b | Alternation (a or b) |
| \1 | Back-reference to group 1 |
| g flag | Global: find all matches |
| i flag | Case-insensitive matching |
| m flag | Multiline: ^ and $ match lines |
| s flag | Dotall: . matches newline too |
Common Validation Patterns
| Item | Value |
|---|---|
| [\w.-]+@[\w.-]+\.\w{2,} | |
| URL | https?://[\w.-]+(?:\.[\w]{2,})(?:/[^\s]*)? |
| US Phone | \(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4} |
| IP Address (v4) | \d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3} |
| Date (MM/DD/YYYY) | \d{2}/\d{2}/\d{4} |
| Hex Color | #?[0-9a-fA-F]{3,8} |
| US ZIP Code | \d{5}(-\d{4})? |
| Strong Password | (?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[!@#$%]).{8,} |
| Slug / URL path | [a-z0-9]+(?:-[a-z0-9]+)* |
Tip: Use landscape orientation for wider tables
Related Tools
Stay Updated
Get notified about new tools, features, and exclusive deals. No spam, ever.