Regex Cheatsheet
Interactive regex reference with searchable patterns, character classes, quantifiers, and examples.
AdSense
Top banner
41 results
| Pattern | Description | Example | Category |
|---|---|---|---|
| . | Any character except newline | a.c matches "abc" | Character Classes |
| \d | Digit (0-9) | \d+ matches "123" | Character Classes |
| \D | Non-digit | \D+ matches "abc" | Character Classes |
| \w | Word character (a-z, A-Z, 0-9, _) | \w+ matches "hello_1" | Character Classes |
| \W | Non-word character | \W matches "@" | Character Classes |
| \s | Whitespace (space, tab, newline) | a\sb matches "a b" | Character Classes |
| \S | Non-whitespace | \S+ matches "hello" | Character Classes |
| [abc] | Character set: a, b, or c | [aeiou] matches vowels | Character Classes |
| [^abc] | Negated set: not a, b, or c | [^0-9] matches non-digits | Character Classes |
| [a-z] | Range: a through z | [A-Za-z] matches letters | Character Classes |
| * | Zero or more | ab*c matches "ac", "abc", "abbc" | Quantifiers |
| + | One or more | ab+c matches "abc", "abbc" | Quantifiers |
| ? | Zero or one (optional) | colou?r matches "color", "colour" | Quantifiers |
| {n} | Exactly n times | \d{3} matches "123" | Quantifiers |
| {n,} | n or more times | \d{2,} matches "12", "123" | Quantifiers |
| {n,m} | Between n and m times | \d{2,4} matches "12", "1234" | Quantifiers |
| *? | Lazy zero or more | <.*?> matches first tag only | Quantifiers |
| +? | Lazy one or more | ".+?" matches first quoted string | Quantifiers |
| ^ | Start of string / line | ^Hello matches "Hello world" | Anchors |
| $ | End of string / line | world$ matches "Hello world" | Anchors |
| \b | Word boundary | \bcat\b matches "cat" not "catch" | Anchors |
| \B | Non-word boundary | \Bcat matches "concat" | Anchors |
| (abc) | Capturing group | (\d+)-(\d+) captures both parts | Groups & References |
| (?:abc) | Non-capturing group | (?:ab)+ matches "abab" | Groups & References |
| (?<name>abc) | Named capturing group | (?<year>\d{4}) captures as "year" | Groups & References |
| \1 | Back-reference to group 1 | (\w+)\s\1 matches "the the" | Groups & References |
| (?=abc) | Positive lookahead | \d(?=px) matches "5" in "5px" | Groups & References |
| (?!abc) | Negative lookahead | \d(?!px) matches "5" in "5em" | Groups & References |
| (?<=abc) | Positive lookbehind | (?<=\$)\d+ matches "100" in "$100" | Groups & References |
| (?<!abc) | Negative lookbehind | (?<!\$)\d+ matches "100" in "100" | Groups & References |
| a|b | Alternation: a or b | cat|dog matches either | Alternation & Flags |
| g | Flag: global (find all matches) | /\d+/g finds all numbers | Alternation & Flags |
| i | Flag: case-insensitive | /hello/i matches "HELLO" | Alternation & Flags |
| m | Flag: multiline (^ and $ per line) | /^start/m matches per line | Alternation & Flags |
| s | Flag: dotAll (. matches newlines) | /a.b/s matches "a\nb" | Alternation & Flags |
| u | Flag: Unicode mode | /\p{L}/u matches Unicode letters | Alternation & Flags |
| ^[\w.-]+@[\w.-]+\.\w{2,}$ | Email (simple) | user@example.com | Common Patterns |
| ^https?://[^\s]+$ | URL (simple) | https://example.com/path | Common Patterns |
| ^\d{1,3}(\.\d{1,3}){3}$ | IPv4 address | 192.168.1.1 | Common Patterns |
| ^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$ | Hex color | #ff0000 or #f00 | Common Patterns |
| ^\d{4}-\d{2}-\d{2}$ | Date (YYYY-MM-DD) | 2024-01-15 | Common Patterns |
Was this page helpful?