Regex Cheatsheet
Tokens, flags, and common patterns reference.
Tokens
| . | Any character (except newline) |
| \d | Digit (0-9) |
| \D | Non-digit |
| \w | Word character (a-z, A-Z, 0-9, _) |
| \W | Non-word character |
| \s | Whitespace (space, tab, newline) |
| \S | Non-whitespace |
| ^ | Start of string (or line in multiline mode) |
| $ | End of string (or line) |
| \b | Word boundary |
| \B | Non-word boundary |
| * | 0 or more (greedy) |
| + | 1 or more (greedy) |
| ? | 0 or 1, or makes a quantifier lazy |
| {n} | Exactly n |
| {n,} | n or more |
| {n,m} | Between n and m |
| [abc] | Any of a, b, or c |
| [^abc] | Anything except a, b, or c |
| [a-z] | Range a through z |
| (...) | Capturing group |
| (?:...) | Non-capturing group |
| (?=...) | Positive lookahead |
| (?!...) | Negative lookahead |
| (?<=...) | Positive lookbehind |
| (?<!...) | Negative lookbehind |
| a|b | a or b |
| \1, \2 | Back-reference to capture group 1, 2 |
Flags
| /g | Global (find all matches) |
| /i | Case-insensitive |
| /m | Multiline (^ and $ match line breaks) |
| /s | Dotall (. matches newline) |
| /u | Unicode |
| /y | Sticky (match from lastIndex) |
Common patterns
| Email (simple) | [^\s@]+@[^\s@]+\.[^\s@]+ |
| URL | https?:\/\/[^\s]+ |
| IPv4 | \b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b |
| Phone (US) | \(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{4} |
| Hex color | #?([a-fA-F0-9]{6}|[a-fA-F0-9]{3}) |
| Date (YYYY-MM-DD) | \d{4}-\d{2}-\d{2} |
| UUID | [0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12} |
| Slug | [a-z0-9]+(?:-[a-z0-9]+)* |
| Whitespace lines | ^\s*$ |
| Trailing whitespace | [ \t]+$ |
JavaScript flavor regex (POSIX flavor differs slightly). For the live tester, use the dedicated regex tester tool. For a deep dive, regular-expressions.info is the best free reference.
About
Quick reference for JavaScript regex: tokens (\d, \w, \b), quantifiers (*, +, ?), groups, lookarounds, and flags. Plus 10 ready-to-use patterns for email, URL, IPv4, etc.
How to use
- Skim the table for what you need.
FAQ
Are these patterns production-ready?+
The simple ones (URL, IPv4) work for 90%+ of cases. Email regex is famously hard - the simple version misses edge cases but covers what you'd actually find in user input.