Regex Cheatsheet

Regular expression syntax reference for quick lookup of common patterns.

Character Matching

.pages.dev.regex-items.char-match.anychar
\dpages.dev.regex-items.char-match.digit
\Dpages.dev.regex-items.char-match.nondigit
\wpages.dev.regex-items.char-match.wordchar
\Wpages.dev.regex-items.char-match.nonwordchar
\spages.dev.regex-items.char-match.whitespace
\Spages.dev.regex-items.char-match.nonwhitespace
\bpages.dev.regex-items.char-match.wordboundary
\Bpages.dev.regex-items.char-match.nonwordboundary
[abc]pages.dev.regex-items.char-match.charset-in
[^abc]pages.dev.regex-items.char-match.charset-notin
[a-z]pages.dev.regex-items.char-match.range
[a-zA-Z]pages.dev.regex-items.char-match.alpha-range
[0-9]pages.dev.regex-items.char-match.digit-range
\pages.dev.regex-items.char-match.escape

Quantifiers

*pages.dev.regex-items.quantifiers.star
+pages.dev.regex-items.quantifiers.plus
?pages.dev.regex-items.quantifiers.optional
{n}pages.dev.regex-items.quantifiers.exact-n
{n,}pages.dev.regex-items.quantifiers.atleast-n
{n,m}pages.dev.regex-items.quantifiers.range-nm
*?pages.dev.regex-items.quantifiers.lazy-star
+?pages.dev.regex-items.quantifiers.lazy-plus
??pages.dev.regex-items.quantifiers.lazy-optional
{n,m}?pages.dev.regex-items.quantifiers.lazy-range

Grouping & Backreferences

(abc)pages.dev.regex-items.grouping.capture
(?:abc)pages.dev.regex-items.grouping.non-capture
(?<name>abc)pages.dev.regex-items.grouping.named-capture
\1pages.dev.regex-items.grouping.backref-num
\k<name>pages.dev.regex-items.grouping.backref-name
(?=abc)pages.dev.regex-items.grouping.lookahead
(?!abc)pages.dev.regex-items.grouping.neg-lookahead
(?<=abc)pages.dev.regex-items.grouping.lookbehind
(?<!abc)pages.dev.regex-items.grouping.neg-lookbehind

Anchors & Boundaries

^pages.dev.regex-items.anchors.start
$pages.dev.regex-items.anchors.end
\bpages.dev.regex-items.anchors.wordboundary
\Bpages.dev.regex-items.anchors.nonwordboundary

Modifiers

gpages.dev.regex-items.modifiers.global
ipages.dev.regex-items.modifiers.insensitive
mpages.dev.regex-items.modifiers.multiline
spages.dev.regex-items.modifiers.dotall
upages.dev.regex-items.modifiers.unicode
ypages.dev.regex-items.modifiers.sticky

Special Constructs

|pages.dev.regex-items.special.alternation
(a|b)pages.dev.regex-items.special.alt-group
[\u4e00-\u9fa5]pages.dev.regex-items.special.chinese-range
[\u4e00-\u9fa5a-zA-Z0-9]pages.dev.regex-items.special.chinese-alnum
\x{hh}pages.dev.regex-items.special.hex-char
\u{hhhh}pages.dev.regex-items.special.unicode-char
\0pages.dev.regex-items.special.null-char
\npages.dev.regex-items.special.newline
\rpages.dev.regex-items.special.carriage-return
\tpages.dev.regex-items.special.tab

Common Regular Expressions

Email^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$
Phone Number^1[3-9]\d{9}$
ID Card Number^\d{17}[\dXx]$
URL^https?://[\w\-]+(\.[\w\-]+)+[/#?]?.*$
IP Address^((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)$
Date^\d{4}[-/](0[1-9]|1[0-2])[-/](0[1-9]|[12]\d|3[01])$
Time^([01]\d|2[0-3]):[0-5]\d(:[0-5]\d)?$
Chinese Characters^[\u4e00-\u9fa5]+$
ZIP Code^[1-9]\d{5}$
Hex Color^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$
Strong Password^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$
License Plate^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤川青藏琼宁][A-Z][A-Z0-9]{5,6}$

Usage Guide

Features

The regex cheatsheet collects common regex syntax across six categories: character matching, quantifiers, grouping & references, anchors & boundaries, modifiers, and special constructs. It also provides complete regex templates for common scenarios like email, phone numbers, ID card numbers, and URLs for quick reference and copying.

Steps

Enter keywords (such as "number", "boundary", "email") in the top search bar to fuzzy-match related syntax. Browse syntax entries under each category: the syntax symbol is on the left, description on the right. In the "Common Regular Expressions" card, hover over a target row and click the copy icon to copy the full regex to clipboard.

Category Guide

Character matching (., \d, \w, etc.) matches single characters; quantifiers (*, +, {n,m}) control match count; grouping & references ((), (?:)) enable extraction and backtracking; anchors & boundaries (^, $, \b) limit match positions; modifiers (g, i, m) change overall matching behavior; special constructs (

Notes

Different languages have slightly different regex escaping rules. When copying to code, note whether double escaping is needed (e.g., \d must be written as \d in JavaScript strings). Common templates are for basic validation only; it is recommended to adjust based on business rules in production environments. Regex performance may degrade in complex backtracking scenarios; avoid excessive nesting and greedy quantifier abuse.