Skip to main content

Regex cheat sheet

40 common patterns grouped by category - click any pattern to test it against your own text.

Email addressEmail & URLs
[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}
Basic RFC-5321 email pattern. e.g. user@example.com
HTTP/HTTPS URLEmail & URLs/i
https?:\/\/[^\s/$.?#].[^\s]*
Matches http:// and https:// URLs. e.g. https://example.com/path?q=1
Domain nameEmail & URLs
(?:[a-zA-Z0-9](?:[a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}
Matches valid domain names. e.g. example.co.uk
IPv4 addressEmail & URLs
(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)
Matches IPv4 in dotted-decimal notation. e.g. 192.168.1.1
IPv6 address (abbreviated)Email & URLs/i
([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::([0-9a-fA-F]{1,4}:)*[0-9a-fA-F]{1,4}
Matches common IPv6 formats. e.g. 2001:db8::1
Slug / URL segmentEmail & URLs
[a-z0-9]+(?:-[a-z0-9]+)*
Lowercase kebab-case slug. e.g. my-page-title
ISO 8601 dateDates & Times
\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])
YYYY-MM-DD date format. e.g. 2024-06-15
ISO 8601 datetimeDates & Times
\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})
Full ISO 8601 datetime with timezone. e.g. 2024-06-15T10:30:00Z
US date MM/DD/YYYYDates & Times
(?:0?[1-9]|1[0-2])\/(?:0?[1-9]|[12]\d|3[01])\/\d{4}
American date format. e.g. 06/15/2024
Time HH:MM(:SS)Dates & Times
(?:[01]?\d|2[0-3]):[0-5]\d(?::[0-5]\d)?
24-hour time, seconds optional. e.g. 14:30:00
Unix timestampDates & Times
\b[1-9]\d{9,12}\b
10–13 digit Unix timestamp (seconds or ms). e.g. 1718447400
Integer (any sign)Numbers
-?\d+
Positive or negative integer. e.g. -42
Decimal numberNumbers
-?\d+(?:\.\d+)?
Integer or decimal. e.g. 3.14
Currency (USD)Numbers
\$[\d,]+(?:\.\d{2})?
USD-style currency with optional cents. e.g. $1,234.56
PercentageNumbers
\d+(?:\.\d+)?%
Number followed by percent sign. e.g. 99.9%
Hexadecimal numberNumbers/i
0x[0-9a-fA-F]+|#[0-9a-fA-F]{3,8}
0x-prefixed hex or CSS hex color. e.g. 0xFF or #1a2b3c
Scientific notationNumbers
-?\d+(?:\.\d+)?[eE][+-]?\d+
Numbers in scientific notation. e.g. 6.022e23
Non-empty stringText & Strings/s
.+
Any non-empty content. e.g. hello
Whitespace onlyText & Strings
^\s+$
String containing only whitespace. e.g.
Word boundary wordText & Strings/g
\b\w+\b
A complete word. e.g. hello
Quoted string (double)Text & Strings
"(?:[^"\\]|\\.)*"
Double-quoted string with escape handling. e.g. "hello \"world\""
Quoted string (single)Text & Strings
'(?:[^'\\]|\\.)*'
Single-quoted string with escape handling. e.g. 'it\'s'
Camel case identifierText & Strings
[a-z][a-zA-Z0-9]*
Camel case variable name. e.g. myVariableName
Snake case identifierText & Strings
[a-z][a-z0-9]*(?:_[a-z0-9]+)*
Underscore-separated lowercase identifier. e.g. my_variable_name
Semver versionCode & Dev
v?(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-[a-zA-Z0-9.]+)?
Semantic version string. e.g. 2.1.0-beta.1
Git commit SHACode & Dev/i
\b[0-9a-f]{7,40}\b
Full or abbreviated Git SHA. e.g. a1b2c3d
UUID v4Code & Dev/i
[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}
UUID version 4. e.g. 550e8400-e29b-4d4a-a716-446655440000
JWT tokenCode & Dev
eyJ[A-Za-z0-9_\-]+\.eyJ[A-Za-z0-9_\-]+\.[A-Za-z0-9_\-]+
JSON Web Token (three base64url parts). e.g. eyJhbGc...
Base64 stringCode & Dev
(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?
Standard base64-encoded string. e.g. SGVsbG8=
CSS hex colorCode & Dev/i
#(?:[0-9a-fA-F]{3,4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})
CSS hex color (3, 4, 6, or 8 digits). e.g. #1a2b3c
HTML tagHTML & Markup/i
<\/?[a-z][a-z0-9]*(?:\s[^>]*)?>
Opening or closing HTML tag. e.g. <div class="box">
HTML commentHTML & Markup
<!--[\s\S]*?-->
HTML comment block. e.g. <!-- comment -->
HTML entityHTML & Markup
&(?:[a-zA-Z]+|#\d+|#x[0-9a-fA-F]+);
Named or numeric HTML entity. e.g. &amp; or &#169;
Markdown headingHTML & Markup/m
^#{1,6}\s+.+$
Markdown H1–H6 heading. e.g. ## My heading
Markdown linkHTML & Markup/g
\[([^\]]+)\]\(([^)]+)\)
Markdown inline link. e.g. [text](https://example.com)
Credit card (generic)Security & Validation
(?:\d[ -]?){13,16}
13–16 digit card number (with optional spaces/hyphens). e.g. 4111 1111 1111 1111
Phone (US)Security & Validation
(?:\+1[-.\s]?)?\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}
US phone number in common formats. e.g. +1 (555) 123-4567
Social Security NumberSecurity & Validation
\d{3}-\d{2}-\d{4}
US SSN format (for testing/validation only). e.g. 123-45-6789
Postal code (US ZIP)Security & Validation
\d{5}(?:-\d{4})?
5-digit or ZIP+4 US postal code. e.g. 90210 or 90210-1234
Strong password checkSecurity & Validation
(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^a-zA-Z\d]).{8,}
Requires lower, upper, digit, symbol, ≥8 chars. e.g. P@ssw0rd!