← all tools
Regex cheat sheet
WebSearchable reference for JavaScript regular expressions.
Character classes
| . | Any character except newline | |
| \w \d \s | Word, digit, whitespace | |
| \W \D \S | NOT word, digit, whitespace | |
| [abc] | Any of a, b, c | |
| [a-z] | Range a to z | |
| [^abc] | NOT a, b, or c | |
| \b | Word boundary |
Quantifiers
| a* | 0 or more a | |
| a+ | 1 or more a | |
| a? | 0 or 1 a | |
| a{3} | Exactly 3 a | |
| a{2,4} | 2 to 4 a | |
| a{3,} | 3 or more a | |
| a*? | Non-greedy (lazy) |
Anchors
| ^ | Start of string / line | |
| $ | End of string / line | |
| \A \Z | Start / end of string (not multiline) |
Groups & alternation
| (abc) | Capture group | |
| (?:abc) | Non-capturing group | |
| (?<name>abc) | Named capture | |
| a|b | a OR b | |
| \1 | Backreference to group 1 | |
| (?=abc) | Positive lookahead | |
| (?!abc) | Negative lookahead | |
| (?<=abc) | Positive lookbehind | |
| (?<!abc) | Negative lookbehind |
Flags
| g | Global — find all matches | |
| i | Case-insensitive | |
| m | Multiline — ^ and $ match line breaks | |
| s | . matches newlines (dotall) | |
| u | Unicode | |
| y | Sticky — match at lastIndex only |
Common patterns
| ^[\w.+-]+@[\w-]+\.[\w.-]+$ | Email (basic) | |
| ^https?://[^\s]+$ | URL | |
| ^\d{4}-\d{2}-\d{2}$ | Date YYYY-MM-DD | |
| ^\+?[1-9]\d{1,14}$ | Phone (E.164) | |
| \b[0-9a-f]{6,8}\b | Hex color (6 or 8) | |
| ^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$ | UUID |