Regex Cheat Sheet & Reference
Complete regular expressions syntax reference with categorized patterns, quantifiers, lookaround assertions, and practical examples.
Common Patterns
/https?:\/\/[^\s]+/https://example.com/path/\b(?:\d{1,3}\.){3}\d{1,3}\b/192.168.1.1/^1[3-9]\d{9}$/13812345678/\d{4}-\d{2}-\d{2}/2024-01-15Character Classes
| Pattern | Name | Example | Description | |
|---|---|---|---|---|
. | Any character | a.c → abc, aXc | Matches any single character except newline | |
\d | Digit | \d+ → 123 | Matches any digit (0-9) | |
\D | Non-digit | \D+ → abc | Matches any non-digit character | |
\w | Word character | \w+ → hello_1 | Matches letters, digits, underscore | |
\W | Non-word character | \W+ → !@# | Matches non-word characters | |
\s | Whitespace | a\sb → a b | Matches space, tab, newline | |
\S | Non-whitespace | \S+ → hello | Matches any non-whitespace character | |
[abc] | Character set | [aeiou] → a, e, i | Matches any character in set | |
[^abc] | Negated set | [^0-9] → a, b | Matches any character not in set | |
[a-z] | Character range | [a-z]+ → hello | Matches any character in range |
Quantifiers
| Pattern | Name | Example | Description | |
|---|---|---|---|---|
* | Zero or more | ab*c → ac, abc, abbc | Matches 0 or more of preceding | |
+ | One or more | ab+c → abc, abbc | Matches 1 or more of preceding | |
? | Zero or one | ab?c → ac, abc | Matches 0 or 1 of preceding | |
{n} | Exact count | a{3} → aaa | Matches exactly n occurrences | |
{n,} | n or more | a{2,} → aa, aaa | Matches n or more occurrences | |
{n,m} | Between n and m | a{2,4} → aa, aaa, aaaa | Matches between n and m occurrences | |
*? | Lazy zero or more | a.*?b → ab | Non-greedy matching | |
+? | Lazy one or more | a.+?b → ab | Non-greedy matching |
Anchors
| Pattern | Name | Example | Description | |
|---|---|---|---|---|
^ | Start of string | ^hello → hello world | Matches at start of string/line | |
$ | End of string | world$ → hello world | Matches at end of string/line | |
\b | Word boundary | \bword\b → the word | Matches word boundary | |
\B | Non-word boundary | \Bword → sword | Matches non-word boundary | |
(?=...) | Positive lookahead | a(?=b) → ab | Matches if followed by pattern | |
(?!...) | Negative lookahead | a(?!b) → ac | Matches if not followed by pattern | |
(?<=...) | Positive lookbehind | (?<=a)b → ab | Matches if preceded by pattern | |
(?<!...) | Negative lookbehind | (?<!a)b → cb | Matches if not preceded by pattern |
Groups
| Pattern | Name | Example | Description | |
|---|---|---|---|---|
(...) | Capturing group | (ab)+ → abab | Captures matched text | |
(?:...) | Non-capturing group | (?:ab)+ → abab | Groups without capturing | |
(?<name>...) | Named group | (?<year>\d{4}) | Captures with name | |
\1 | Backreference | (\w)\1 → aa, bb | Matches captured group again | |
a|b | Alternation | cat|dog → cat, dog | Matches either expression |
Assertions
| Pattern | Name | Example | Description | |
|---|---|---|---|---|
(?=...) | Positive lookahead | \d(?=px) → 10px | Assert pattern follows | |
(?!...) | Negative lookahead | \d(?!px) → 10em | Assert pattern does not follow | |
(?<=...) | Positive lookbehind | (?<=\$)\d+ → $100 | Assert pattern precedes | |
(?<!...) | Negative lookbehind | (?<!\$)\d+ → €100 | Assert pattern does not precede |
Flags
| Pattern | Name | Example | Description | |
|---|---|---|---|---|
g | Global | /a/g → a, a, a | Find all matches, not just first | |
i | Case insensitive | /abc/i → ABC, abc | Ignore case in matching | |
m | Multiline | /^a/m → ... a | ^ and $ match line boundaries | |
s | DotAll / Singleline | /a.*b/s → a b | . matches newlines too | |
u | Unicode | /\u{1F600}/u | Enable Unicode support |
What is Regex Cheat Sheet & Reference?
Regex Cheat Sheet & Reference is a comprehensive quick-reference guide for regular expression syntax covering JavaScript PCRE compatible patterns anchors quantifiers character classes groups backreferences and lookaround assertions. Regular expressions are a power tool for text processing but their dense syntax is notoriously difficult to memorize even experienced developers regularly look up the difference between greedy and lazy quantifiers the exact syntax for positive lookaheads or which character classes need escaping inside brackets. This cheat sheet organizes syntax into logically grouped sections Characters Literals Character Classes Shorthands Anchors Boundaries Quantifiers Greedy Lazy Possessive Groups Backreferences Lookahead Lookbehind Assertions Flags Modifiers Substitution Patterns and Common Recipes. Each entry includes pattern syntax plain-English explanation and a testable working example. The Common Recipes section provides production-ready patterns for the forty plus most frequent regex tasks email validation IPv4 IPv6 addresses phone numbers URLs dates credit card numbers password complexity HTML tag extraction and more. Pattern entries include copy buttons and direct links to the Regex Tester for immediate experimentation.
When to Use Regex Cheat Sheet & Reference
Use when building regex patterns for form validation, looking up lookaround syntax, finding pre-built regex recipes for common tasks, memorizing quantifier behavior, or teaching regex concepts to teammates.
How to Use Regex Cheat Sheet & Reference
Browse categorized syntax sections or search for a specific concept. Each entry shows syntax, explanation, and a working example. Click Test to jump directly to the Regex Tester with the pattern pre-loaded.
Related Tools
Regex Tester & Debugger
Test regular expressions live with match highlighting, group capture display, and detailed regex execution explanation.
Email Regex Validator & Pattern
Validate email addresses against RFC 5322 compliant regex patterns with detailed explanation of common email regex approaches.
Phone Number Regex Validator
Validate and format international and national phone numbers with country-aware regex patterns. Support E.164 standard format.