Regex Patterns Cheatsheet
Regular expression patterns for pattern matching, character classes, quantifiers, and advanced techniques.
| Pattern | Description | Example | Matches | Category |
|---|---|---|---|---|
| . | Match any single character | /a.c/ | abc, adc, aec | Basics |
| \d | Match any digit [0-9] | /\d+/ | 123, 456 | Classes |
| \D | Match any non-digit | /\D+/ | abc, xyz | Classes |
| \w | Match word character [a-zA-Z0-9_] | /\w+/ | hello123 | Classes |
| \W | Match non-word character | /\W+/ | @#$% | Classes |
| \s | Match whitespace | /\s+/ | spaces, tabs, newlines | Classes |
| \S | Match non-whitespace | /\S+/ | word, text | Classes |
| [abc] | Match any character in set | /[aeiou]/ | a, e, i, o, u | Classes |
| [^abc] | Match any character NOT in set | /[^0-9]/ | abc, xyz | Classes |
| * | Match 0 or more | /a*b/ | b, ab, aab, aaab | Quantifiers |
| + | Match 1 or more | /a+b/ | ab, aab, aaab | Quantifiers |
| ? | Match 0 or 1 | /a?b/ | b, ab | Quantifiers |
| {n} | Match exactly n times | /a{3}/ | aaa | Quantifiers |
| {n,m} | Match between n and m times | /a{2,4}/ | aa, aaa, aaaa | Quantifiers |
| ^ | Match start of string | /^hello/ | hello world | Anchors |
| $ | Match end of string | /world$/ | hello world | Anchors |
| \b | Match word boundary | /\bword\b/ | word in phrase | Anchors |
| (group) | Capture group | /(\d{3})/ | 123 in 123-456 | Groups |
| (?:group) | Non-capturing group | /(?:cat|dog)/ | cat or dog | Groups |
| (?=lookahead) | Positive lookahead | /\d(?=px)/ | 5 in 5px | Advanced |
| (?!negative) | Negative lookahead | /\d(?!px)/ | 5 in 5em | Advanced |
| | | Alternation (OR) | /(cat|dog)/ | cat or dog | Groups |