Regex Cheatsheet
Complete regular expression reference with interactive live tester.
Character Classes
| Pattern | Description | Example |
| . | Any character except newline | a.c → abc, a1c |
| \d | Digit [0-9] | \d+ → 123 |
| \D | Non-digit [^0-9] | \D+ → abc |
| \w | Word char [a-zA-Z0-9_] | \w+ → hello_1 |
| \W | Non-word char | \W → @, ! |
| \s | Whitespace [ \t\n\r\f] | a\sb → a b |
| \S | Non-whitespace | \S+ → hello |
| [abc] | Character set (a, b, or c) | [aeiou] → vowels |
| [^abc] | Negated set (not a, b, c) | [^0-9] → non-digits |
| [a-z] | Range (a to z) | [A-Za-z]+ → words |
Quantifiers
| Pattern | Description | Example |
| * | 0 or more (greedy) | ab*c → ac, abc, abbc |
| + | 1 or more (greedy) | ab+c → abc, abbc |
| ? | 0 or 1 (optional) | colou?r → color, colour |
| {n} | Exactly n times | \d{3} → 123 |
| {n,} | n or more times | \d{2,} → 12, 123, 1234 |
| {n,m} | Between n and m times | \d{2,4} → 12, 123, 1234 |
| *? | 0 or more (lazy) | <.*?> → first tag only |
| +? | 1 or more (lazy) | ".+?" → first quoted |
Anchors & Boundaries
| Pattern | Description | Example |
| ^ | Start of string/line | ^Hello → starts with Hello |
| $ | End of string/line | world$ → ends with world |
| \b | Word boundary | \bcat\b → cat (not cats) |
| \B | Non-word boundary | \Bcat → scat, bobcat |
Groups & Lookaround
| Pattern | Description | Example |
| (abc) | Capturing group | (ab)+ → ab, abab |
| (?:abc) | Non-capturing group | (?:ab)+ → no capture |
| (?<name>) | Named group | (?<year>\d{4}) |
| \1 | Backreference to group 1 | (\w+)\s\1 → the the |
| a|b | Alternation (a or b) | cat|dog → cat or dog |
| (?=abc) | Positive lookahead | \d(?=px) → 5 in 5px |
| (?!abc) | Negative lookahead | \d(?!px) → 5 in 5em |
| (?<=abc) | Positive lookbehind | (?<=\$)\d+ → 50 in $50 |
| (?<!abc) | Negative lookbehind | (?<!\$)\d+ → non-price |
Common Patterns
| Use Case | Pattern | Notes |
| Email | [\w.-]+@[\w.-]+\.\w{2,} | Basic email match |
| URL | https?://[\w.-]+(?:/\S*)? | HTTP/HTTPS URLs |
| IPv4 | \d{1,3}(?:\.\d{1,3}){3} | Basic IP address |
| Phone | \+?[\d\s()-]{7,15} | International format |
| Hex Color | #(?:[0-9a-fA-F]{3}){1,2} | #fff or #ffffff |
| Date | \d{4}-\d{2}-\d{2} | YYYY-MM-DD format |
Regex API
Test regex patterns programmatically:
curl "https://ai.doxx.lat/api/regex?pattern=\d%2B&test=hello123world"
Free API. No signup. CORS enabled.