Regex Cheat Sheet
Quick reference guide for all regular expression syntax and metacharacters.
About This Cheat Sheet
This cheat sheet provides a comprehensive overview of regular expression syntax, patterns, and metacharacters. Keep it handy when you're crafting regex patterns or debugging existing ones.
Tip: Bookmark this page and refer to it whenever you need a quick refresher on regex syntax. You can also practice these patterns in our Regex Tester.
Character Classes
| Pattern | Description | Example |
|---|---|---|
[abc] | Matches a, b, or c | Matches "a" in "cat" |
[^abc] | Matches any except a, b, or c | Matches "d" in "dog" |
[a-z] | Matches any lowercase letter | Matches "c" in "Cat" |
[A-Z] | Matches any uppercase letter | Matches "C" in "Cat" |
[0-9] | Matches any digit | Matches "3" in "a3b" |
\w | Matches word characters (a-z, A-Z, 0-9, _) | Matches "a", "3", "_" in "a3_" |
\d | Matches any digit (same as [0-9]) | Matches "5" in "x5y" |
\s | Matches whitespace | Matches space in "hello world" |
Quantifiers
| Pattern | Description | Example |
|---|---|---|
* | Zero or more occurrences | a* matches "", "a", "aa", "aaa" |
+ | One or more occurrences | a+ matches "a", "aa", "aaa" |
? | Zero or one occurrence | a? matches "" or "a" |
{n} | Exactly n occurrences | a{3} matches "aaa" |
{n,m} | Between n and m occurrences | a{2,4} matches "aa", "aaa", "aaaa" |
{n,} | n or more occurrences | a{2,} matches "aa", "aaa", "aaaa" |
Anchors
| Pattern | Description | Example |
|---|---|---|
^ | Start of string | ^hello matches "hello" in "hello world" |
$ | End of string | world$ matches "world" in "hello world" |
\b | Word boundary | \bcat\b matches "cat" but not "cater" |
\B | Non-word boundary | \Bcat\B matches "cat" in "category" |
Special Characters
| Pattern | Description | Example |
|---|---|---|
. | Any single character (except newline) | a.b matches "aab", "abb", "acb" |
\| | OR operator | cat\|dog matches "cat" or "dog" |
(...) | Capturing group | (cat) matches and captures "cat" |
(?:...) | Non-capturing group | (?:cat) matches "cat" without capturing |
\n | Matches nth captured group | (\w+) \1 matches "word word" |
Escape Sequences
| Pattern | Description | Example |
|---|---|---|
\\. | Escapes special characters | \\* matches literal "*" |
\\d | Digit (0-9) | \\d matches "7" |
\\D | Non-digit | \\D matches "a" in "a7" |
\\w | Word character | \\w matches "x" in "x7" |
\\W | Non-word character | \\W matches " " in "hello world" |
\\s | Whitespace | \\s matches space, tab, newline |
\\S | Non-whitespace | \\S matches "h" in " h " |
🔥
Popular Patterns
📧
Email Address
Validate standard email formats. Includes support for common domains and subdomains.
Try Email Regex →📅
Dates (YYYY-MM-DD)
Match dates in ISO 8601 format. Validates year, month, and day structure.
Try Date Regex →📱
US Phone Number
Match various US phone formats including dashes, dots, and parentheses.
Try Phone Regex →