Regex Cheat Sheet
Regular expression syntax cheat sheet, containing common patterns, character sets, quantifiers, and other references
⚡ Quick Test
Test results will appear here
📝 Common Characters
| Pattern | Instructions | Example |
|---|---|---|
.
|
Any character (except newline) | a.c matches abc, aac |
\d
|
Digit [0-9] | \d{3} matches 123 |
\D
|
non-digit | \D+ matches abc |
\w
|
Alphanumeric underscore [a-zA-Z0-9_] | \w+ matches word_123 |
\W
|
non-word character | \W+ matches !@# |
\s
|
Whitespace characters (space, tab, etc.) | \s+ matches whitespace |
\S
|
non-whitespace character | \S+ matches abc |
🔐 Escape Characters
| Pattern | Instructions | Example |
|---|---|---|
\.
|
Matches the dot itself | \.com matches .com |
\\
|
Matches backslash | \\ matches \ |
\*
|
Matches asterisk | \* matches * |
\+
|
Matches plus sign | \+ matches + |
\?
|
Matches question mark | \? matches ? |
\(
|
Matches left parenthesis | \( matches ( |
\)
|
Matches right parenthesis | \) matches ) |
\[
|
Matches left bracket | \[ matches [ |
\]
|
Matches right bracket | \] matches ] |
\{
|
Matches left brace | \{ matches { |
\}
|
Matches right brace | \} matches } |
\|
|
Matches vertical bar | \| matches | |
\-
|
Matches hyphen | \- matches - |
\^
|
Matches caret | \^ matches ^ |
\$
|
Matches dollar sign | \$ matches $ |
🔢 Quantifiers
| Pattern | Instructions | Example |
|---|---|---|
*
|
0 or more times | ab* matches a, ab, abb |
+
|
1 or more times | ab+ matches ab, abb |
?
|
0 or 1 time | ab? matches a, ab |
{n}
|
Exactly n times | a{3} matches aaa |
{n,}
|
At least n times | a{2,} matches aa, aaa |
{n,m}
|
Between n and m times | a{2,4} matches aa, aaa, aaaa |
*?
|
Non-greedy 0 or more times | <.+?> matches shortest HTML tag |
+?
|
Non-greedy 1 or more times | <.+?> matches shortest HTML tag |
📍 Boundary Anchors
| Pattern | Instructions | Example |
|---|---|---|
^
|
string start | ^abc matches abc... |
$
|
string end | abc$ matches ...abc |
\b
|
word boundary | \bword\b matches word |
\B
|
Non-word boundary | \Bword\B matches sword |
\A
|
String start (multiline) | \Aabc matches abc |
\Z
|
String end (multiline) | abc\Z matches abc |
🎨 Character Sets
| Pattern | Instructions | Example |
|---|---|---|
[abc]
|
Matches a, b, or c | [abc] matches a, b, c |
[^abc]
|
Does not match a, b, or c | [^abc] matches d, e, f |
[a-z]
|
Lowercase letters | [a-z] matches a to z |
[A-Z]
|
Uppercase letters | [A-Z] matches A to Z |
[0-9]
|
Digits | [0-9] matches 0 to 9 |
[a-zA-Z]
|
All letters | [a-zA-Z] matches a-z, A-Z |
[\u4e00-\u9fa5]
|
Chinese characters | [\u4e00-\u9fa5]+ matches Chinese characters |
📦 Grouping and Capturing
| Pattern | Instructions | Example |
|---|---|---|
(abc)
|
capturing group | (\d{3}) matches and captures digits |
(?:abc)
|
Non-capturing group | (?:\d{3}) matches but does not capture |
(?
|
Named capturing group |
(?
|
\1
|
Reference group 1 | (\w)\1 matches aa, bb |
\2
|
Reference group 2 | (\w)(\w)\2 matches aba |
(?=abc)
|
positive lookahead | \w+(?=\.com) matches domain name |
(?!abc)
|
negative lookahead | \w+(?!\.com) does not match .com |
(?<=abc)
|
positive lookbehind | (?<=\$)\d+ matches amount |
(?
|
negative lookbehind | (? |
🎯 Common Regex Patterns
| purpose | regular expression | Instructions |
|---|---|---|
^\w+@\w+\.\w+$
|
Basic email format | |
| phone number |
^1[3-9]\d{9}$
|
China mainland phone number |
| ID number |
^\d{17}[\dXx]$
|
18-digit ID number |
| URL |
https?:\/\/[\w\-\.]+(:\d+)?(\/.*)?
|
HTTP/HTTPS link |
| IP address |
^(\d{1,3}\.){3}\d{1,3}$
|
IPv4 address |
| date |
^\d{4}-\d{2}-\d{2}$
|
YYYY-MM-DD format |
| time |
^\d{2}:\d{2}:\d{2}$
|
HH:MM:SS format |
| Chinese characters |
[\u4e00-\u9fa5]
|
Single Chinese character |
| HTML tag |
<[^>]+>
|
Matches HTML tag |
| hex color |
^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$
|
#FFF or #FFFFFF |
| username |
^[a-zA-Z0-9_]{3,16}$
|
3-16 characters |
| strong password |
^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).{8,}$
|
Uppercase + lowercase + number + 8 chars |
🚩 Flags
| flag | Instructions | Example |
|---|---|---|
g
|
Global match, find all matches | /a/g matches all a |
i
|
Ignore case | /abc/i matches ABC, abc |
m
|
Multiline pattern, ^$ matches line start/end | /^abc/m matches line start |
s
|
Single-line pattern, . matches newline | /a.b/s matches a\nb |
u
|
Unicode pattern | /\u{1F600}/u matches emoji |
y
|
Sticky match, starts from lastIndex | /a/y strictly starts from index |
💡 Instructions
Quick copy:
Click the button below the table to quickly copy common regular expressions
Real-time test: Enter text and regular expression in the top test area, click "Test Match" to see results
JavaScript example:
Common methods:
• test() - Test if matches
• exec() - Execute matches and return result
• match() - Find matches
• replace() - Replace matches
• split() - Split string by pattern
Real-time test: Enter text and regular expression in the top test area, click "Test Match" to see results
JavaScript example:
const regex = /\d+/g;
const matches = "abc123".match(regex); // ["123"]
Common methods:
• test() - Test if matches
• exec() - Execute matches and return result
• match() - Find matches
• replace() - Replace matches
• split() - Split string by pattern
💡 About Regex Cheat Sheet:
Our comprehensive
regex cheat sheet
is a complete reference guide for regular expressions. Includes common patterns, character sets, quantifiers, anchors, grouping, and flags. Test your regular expressions in real-time with the built-in tester. Perfect for developers, data analysts, and anyone working with pattern matching and text validation.
📝 Regex Cheat Sheet Features:
• Complete regular expression syntax reference
• Common character sets and patterns
• Quantifiers and repetition operators
• Anchors and boundaries
• Grouping and capturing
• Lookahead and lookbehind assertions
• Common regex patterns (email, phone, URL, etc.)
• Flags and modifiers reference
• Real-time regex testing tool
🔍 Regex Use Cases:
• Form validation (email, phone, password)
• Data extraction from text
• String parsing and manipulation
• Search and replace operations
• Log file analysis
• Web scraping and data cleaning
• Code refactoring and automation
• Complete regular expression syntax reference
• Common character sets and patterns
• Quantifiers and repetition operators
• Anchors and boundaries
• Grouping and capturing
• Lookahead and lookbehind assertions
• Common regex patterns (email, phone, URL, etc.)
• Flags and modifiers reference
• Real-time regex testing tool
🔍 Regex Use Cases:
• Form validation (email, phone, password)
• Data extraction from text
• String parsing and manipulation
• Search and replace operations
• Log file analysis
• Web scraping and data cleaning
• Code refactoring and automation