Regex Tools

Regex Cheat Sheet & Reference

Complete regular expressions syntax reference with categorized patterns, quantifiers, lookaround assertions, and practical examples.

regexcheat sheetreferencepatternsyntax

Common Patterns

Email
/^[^\s@]+@[^\s@]+\.[^\s@]+$/
Example: test@example.com
Basic email validation
URL
/https?:\/\/[^\s]+/
Example: https://example.com/path
Match HTTP/HTTPS URLs
IPv4 Address
/\b(?:\d{1,3}\.){3}\d{1,3}\b/
Example: 192.168.1.1
IPv4 address pattern
Chinese Phone
/^1[3-9]\d{9}$/
Example: 13812345678
Mainland China mobile number
Date (YYYY-MM-DD)
/\d{4}-\d{2}-\d{2}/
Example: 2024-01-15
ISO date format

Character Classes

PatternNameExampleDescription
.Any charactera.c → abc, aXcMatches any single character except newline
\dDigit\d+ → 123Matches any digit (0-9)
\DNon-digit\D+ → abcMatches any non-digit character
\wWord character\w+ → hello_1Matches letters, digits, underscore
\WNon-word character\W+ → !@#Matches non-word characters
\sWhitespacea\sb → a bMatches space, tab, newline
\SNon-whitespace\S+ → helloMatches any non-whitespace character
[abc]Character set[aeiou] → a, e, iMatches any character in set
[^abc]Negated set[^0-9] → a, bMatches any character not in set
[a-z]Character range[a-z]+ → helloMatches any character in range

Quantifiers

PatternNameExampleDescription
*Zero or moreab*c → ac, abc, abbcMatches 0 or more of preceding
+One or moreab+c → abc, abbcMatches 1 or more of preceding
?Zero or oneab?c → ac, abcMatches 0 or 1 of preceding
{n}Exact counta{3} → aaaMatches exactly n occurrences
{n,}n or morea{2,} → aa, aaaMatches n or more occurrences
{n,m}Between n and ma{2,4} → aa, aaa, aaaaMatches between n and m occurrences
*?Lazy zero or morea.*?b → abNon-greedy matching
+?Lazy one or morea.+?b → abNon-greedy matching

Anchors

PatternNameExampleDescription
^Start of string^hello → hello worldMatches at start of string/line
$End of stringworld$ → hello worldMatches at end of string/line
\bWord boundary\bword\b → the wordMatches word boundary
\BNon-word boundary\Bword → swordMatches non-word boundary
(?=...)Positive lookaheada(?=b) → abMatches if followed by pattern
(?!...)Negative lookaheada(?!b) → acMatches if not followed by pattern
(?<=...)Positive lookbehind(?<=a)b → abMatches if preceded by pattern
(?<!...)Negative lookbehind(?<!a)b → cbMatches if not preceded by pattern

Groups

PatternNameExampleDescription
(...)Capturing group(ab)+ → ababCaptures matched text
(?:...)Non-capturing group(?:ab)+ → ababGroups without capturing
(?<name>...)Named group(?<year>\d{4})Captures with name
\1Backreference(\w)\1 → aa, bbMatches captured group again
a|bAlternationcat|dog → cat, dogMatches either expression

Assertions

PatternNameExampleDescription
(?=...)Positive lookahead\d(?=px) → 10pxAssert pattern follows
(?!...)Negative lookahead\d(?!px) → 10emAssert pattern does not follow
(?<=...)Positive lookbehind(?<=\$)\d+ → $100Assert pattern precedes
(?<!...)Negative lookbehind(?<!\$)\d+ → €100Assert pattern does not precede

Flags

PatternNameExampleDescription
gGlobal/a/g → a, a, aFind all matches, not just first
iCase insensitive/abc/i → ABC, abcIgnore case in matching
mMultiline/^a/m → ... a^ and $ match line boundaries
sDotAll / Singleline/a.*b/s → a b. matches newlines too
uUnicode/\u{1F600}/uEnable 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.