Regex Patterns Cheatsheet

Regular expression patterns for pattern matching, character classes, quantifiers, and advanced techniques.

PatternDescriptionExampleMatchesCategory
.Match any single character/a.c/abc, adc, aecBasics
\dMatch any digit [0-9]/\d+/123, 456Classes
\DMatch any non-digit/\D+/abc, xyzClasses
\wMatch word character [a-zA-Z0-9_]/\w+/hello123Classes
\WMatch non-word character/\W+/@#$%Classes
\sMatch whitespace/\s+/spaces, tabs, newlinesClasses
\SMatch non-whitespace/\S+/word, textClasses
[abc]Match any character in set/[aeiou]/a, e, i, o, uClasses
[^abc]Match any character NOT in set/[^0-9]/abc, xyzClasses
*Match 0 or more/a*b/b, ab, aab, aaabQuantifiers
+Match 1 or more/a+b/ab, aab, aaabQuantifiers
?Match 0 or 1/a?b/b, abQuantifiers
{n}Match exactly n times/a{3}/aaaQuantifiers
{n,m}Match between n and m times/a{2,4}/aa, aaa, aaaaQuantifiers
^Match start of string/^hello/hello worldAnchors
$Match end of string/world$/hello worldAnchors
\bMatch word boundary/\bword\b/word in phraseAnchors
(group)Capture group/(\d{3})/123 in 123-456Groups
(?:group)Non-capturing group/(?:cat|dog)/cat or dogGroups
(?=lookahead)Positive lookahead/\d(?=px)/5 in 5pxAdvanced
(?!negative)Negative lookahead/\d(?!px)/5 in 5emAdvanced
|Alternation (OR)/(cat|dog)/cat or dogGroups