Regex Cheatsheet - Regular Expression Quick Reference
Quick reference for regular expression patterns. Character classes, quantifiers, anchors, and common patterns.
.Any single character except newline
Example: a.c → abc, aac
\dDigit [0-9]
Example: \d+ → 123
\DNon-digit
Example: \D+ → abc
\wWord character
Example: \w+ → hello_world
\WNon-word character
Example: \W+ → @#$
\sWhitespace
Example: \s+ → " "
\SNon-whitespace
Example: \S+ → hello
[abc]Match a, b, or c
Example: [aeiou] → a
[^abc]Not a, b, or c
Example: [^0-9] → a
[a-z]Lowercase letter
Example: [a-z]+ → hello
[A-Z]Uppercase letter
Example: [A-Z]+ → HELLO
[0-9]Digit
Example: [0-9]+ → 123
[a-zA-Z]Letter
Example: [a-zA-Z]+ → Hello
^Start of line
Example: ^Hello → Hello world
$End of line
Example: world$ → Hello world
\bWord boundary
Example: \bcat\b → cat
\BNon-word boundary
Example: \Bcat → category
*Zero or more
Example: a* → "" or "aaa"
+One or more
Example: a+ → "a" or "aaa"
?Zero or one
Example: colou?r → color or colour
{n}Exactly n times
Example: a{3} → aaa
{n,}At least n times
Example: a{2,} → aa or aaa
{n,m}Between n and m times
Example: a{2,4} → aa, aaa, aaaa
*?Lazy zero or more
Example: <.*?> → <a>
+?Lazy one or more
Example: <.+?> → <a>
(abc)Capturing group
Example: (\d+)-\1 → 123-123
(?:abc)Non-capturing group
Example: (?:abc)+ → abcabc
(?<name>abc)Named capturing group
Example: (?<year>\d{4})
|Alternation
Example: cat|dog → cat or dog
(?=abc)Positive lookahead
Example: \w+(?=ing) → run in running
(?!abc)Negative lookahead
Example: \w+(?!ing) → run in run
(?<=abc)Positive lookbehind
Example: (?<=\$)\d+ → 100 in $100
(?<!abc)Negative lookbehind
Example: (?<!\$)\d+ → 100 in €100
\\Backslash
Example: C:\\Windows
\.Literal dot
Example: \.com → .com
\*Literal asterisk
Example: a\*b → a*b
\+Literal plus
Example: a\+b → a+b
\?Literal question mark
Example: a\?b → a?b
\[Literal [
Example: \[abc\] → [abc]
\(Literal (
Example: \(abc\) → (abc)
\^Literal ^
Example: 2\^3 → 2^3
\$Literal $
Example: \$100 → $100
\nNewline
Example: line1\nline2
\tTab
Example: col1\tcol2
\rCarriage return
Example: \r\n (Windows)
iCase insensitive
Example: /hello/i → HELLO
gGlobal match
Example: /a/g → all a's
mMultiline
Example: /^a/m → a at line start
sDot matches newline
Example: /.+/s → includes \n
uUnicode
Example: /\u{1F600}/u → 😀
ySticky
Example: /\d+/y → consecutive digits
^[\w-]+@[\w-]+\.[\w-]+$Email address
Example: user@example.com
^https?://[^\s]+$URL
Example: https://example.com
^\d{4}-\d{2}-\d{2}$Date YYYY-MM-DD
Example: 2024-01-15
^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$IP address
Example: 192.168.1.1
^\+?[\d\s-()]{7,}$Phone number
Example: +86 138-0000-0000
^\d{6}$6-digit code
Example: 123456
\b[\w-]+\bWord
Example: hello-world
<[^>]+>HTML tag
Example: <div class="test">
^\d+$Digits only
Example: 12345
^[a-zA-Z]+$Letters only
Example: Hello
^[a-zA-Z0-9_]+$Word characters
Example: hello_world123
^\S+$Non-whitespace
Example: no-spaces
\d{4}-\d{4}-\d{4}-\d{4}Credit card
Example: 1234-5678-9012-3456
^#[0-9A-Fa-f]{6}$Hex color
Example: #FF5733
^[A-Za-z0-9+/]{4}*[A-Za-z0-9+/]{2}==$Base64 encoded
Example: SGVsbG8=
\b\d{1,3}(,\d{3})*(\.\d+)?\bNumber with commas
Example: 1,234,567.89
^[a-z]+(-[a-z]+)*$Kebab-case
Example: hello-world-test
^[a-z]+(_[a-z]+)*$Snake_case
Example: hello_world_test
^[A-Z][a-z]+([A-Z][a-z]+)*$CamelCase
Example: HelloWorldTest
70 of 70 patterns shown
Related Tools
More Code & Dev Tools
SQL Formatter
Format and beautify SQL queries online. Improve SQL readabil...
JavaScript Formatter
Format and beautify JavaScript code online. Improve code rea...
HTML Formatter
Format and minify HTML online. Beautify HTML code or compres...
Code Share
Create and share code snippets online. Syntax highlighting a...
IP Calculator
Calculate IP ranges, subnet masks, and CIDR notation. Networ...
Code Formatter
Format and beautify code online. Support multiple languages ...
Color Converter
Convert between HEX, RGB, HSL color formats. Color picker wi...
Color Extractor
Extract colors from images online. Get dominant colors and c...
API Tester
Test HTTP APIs online with support for GET, POST, PUT, DELET...
cURL Converter
Convert cURL commands to Python, JavaScript, PHP, Go, and mo...
CSS Gradient Generator
Generate CSS gradients online. Linear and radial gradients w...
JavaScript Obfuscator
Obfuscate and protect JavaScript code. Make your code harder...