Last updated: April 12, 2026
Regex Syntax Cheatsheet
Quick Answer
This cheatsheet covers essential regex syntax: character classes, quantifiers, anchors, groups, and lookaround assertions. Use it as a quick reference when writing regular expressions in any language.
Characters
| Command | Description |
|---|---|
| . | Match any single character (except newline by default) a.c matches "abc", "a1c", "a-c" |
| \d | Match any digit (0-9) \d{3} matches "123" |
| \w | Match any word character (letter, digit, underscore) \w+ matches "hello_123" |
| \s | Match any whitespace (space, tab, newline) hello\sworld matches "hello world" |
| \D, \W, \S | Negated versions: non-digit, non-word, non-whitespace |
Character Classes
| Command | Description |
|---|---|
| [abc] | Match any one character in the set [aeiou] matches any vowel |
| [^abc] | Match any character NOT in the set [^0-9] matches non-digits |
| [a-z] | Match any character in the range [A-Za-z] matches any letter |
Anchors
| Command | Description |
|---|---|
| ^ | Match start of string (or line in multiline mode) ^Hello matches "Hello world" |
| $ | Match end of string (or line in multiline mode) world$ matches "hello world" |
| \b | Match word boundary \bcat\b matches "cat" but not "category" |
Quantifiers
| Command | Description |
|---|---|
| * | Match 0 or more of the preceding element (greedy) ab*c matches "ac", "abc", "abbc" |
| + | Match 1 or more of the preceding element (greedy) ab+c matches "abc", "abbc" but not "ac" |
| ? | Match 0 or 1 of the preceding element (optional) colou?r matches "color" and "colour" |
| {n} | Match exactly n occurrences \d{4} matches "2026" |
| {n,m} | Match between n and m occurrences \d{2,4} matches "12", "123", "1234" |
| *?, +?, ?? | Lazy (non-greedy) versions — match as few as possible <.+?> matches "<b>" not "<b>text</b>" |
Groups
| Command | Description |
|---|---|
| (abc) | Capturing group — matches and captures "abc" (\d{3})-(\d{4}) captures area and number |
| (?:abc) | Non-capturing group — matches but does not capture (?:https?://) matches protocol without capturing |
| (?<name>abc) | Named capturing group (?<year>\d{4}) captures as "year" |
| a|b | Alternation — match a OR b cat|dog matches "cat" or "dog" |
Lookaround
| Command | Description |
|---|---|
| (?=abc) | Positive lookahead — match if followed by abc \d+(?=px) matches "12" in "12px" |
| (?!abc) | Negative lookahead — match if NOT followed by abc \d+(?!px) matches "12" in "12em" |
| (?<=abc) | Positive lookbehind — match if preceded by abc (?<=\$)\d+ matches "50" in "$50" |
| (?<!abc) | Negative lookbehind — match if NOT preceded by abc (?<!\$)\d+ matches "50" in "€50" |
Frequently Asked Questions
More Cheatsheets
Git Commands Cheatsheet
This cheatsheet covers the 40 most essential Git commands grouped by workflow: setup, staging, branc...
Docker Commands Cheatsheet
This cheatsheet covers 35 essential Docker commands for managing containers, images, volumes, and ne...
Linux Commands Cheatsheet
This cheatsheet covers 40 essential Linux/Unix commands for daily development: file navigation, text...
HTTP Status Codes Cheatsheet
HTTP status codes are 3-digit numbers returned by servers. 1xx = informational, 2xx = success, 3xx =...