Learn
Cheatsheet
Regular Expressions
Pattern matching syntax for search and validation.
Character Classes
| . | Any character (except newline) |
| \d | Digit [0-9] |
| \D | Non-digit |
| \w | Word character [a-zA-Z0-9_] |
| \W | Non-word character |
| \s | Whitespace |
| [abc] | a, b, or c |
| [^abc] | Anything except a, b, c |
| [a-z] | Lowercase letter |
Quantifiers
| * | 0 or more |
| + | 1 or more |
| ? | 0 or 1 (optional) |
| {3} | Exactly 3 |
| {2,5} | Between 2 and 5 |
| {3,} | 3 or more |
| *? / +? | Lazy (match as few as possible) |
Anchors & Groups
| ^ | Start of string |
| $ | End of string |
| \b | Word boundary |
| (abc) | Capturing group |
| (?:abc) | Non-capturing group |
| a|b | a or b |
| (?=abc) | Positive lookahead |
| (?!abc) | Negative lookahead |
Common Patterns
| ^[\w.-]+@[\w.-]+\.\w{2,}$ | Email (basic) |
| ^\d+$ | Only digits |
| ^\d{4}-\d{2}-\d{2}$ | Date YYYY-MM-DD |
| #[0-9a-fA-F]{6} | Hex color |
| ^https?:// | URL starting with http(s) |