Regex Library
100 Essential Regex Patterns
Powerful Regular Expressions • Features & Use CasesA curated selection of the most useful regular expressions for validation, extraction, and cleaning. Copy, adapt, and use them in JavaScript, Python, PHP, or any modern language.
| Pattern | Regex |
|---|---|
|
Email Address
Most common validation
|
^[^\s@]+@[^\s@]+\.[^\s@]+$ |
|
Strong Password
8+ chars, upper, lower, number, symbol
|
^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$ |
|
URL / Website
http, https, optional www
|
https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b |
|
IPv4 Address
0.0.0.0 – 255.255.255.255
|
^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$ |
|
Hex Color Code
#RGB or #RRGGBB
|
^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$ |
|
Date (YYYY-MM-DD)
ISO format
|
^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$ |
|
Phone (International)
+ and digits
|
^\+?[1-9]\d{7,14}$ |
|
Username
3–20 chars, alphanumeric + _
|
^[a-zA-Z0-9_]{3,20}$ |
|
Slug / URL-friendly
lowercase-with-hyphens
|
^[a-z0-9]+(?:-[a-z0-9]+)*$ |
|
UUID / GUID
Standard format
|
^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$ |
|
IPv6 Address
Full & compressed
|
^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|(([0-9a-fA-F]{1,4}:){0,6}[0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:){0,6}[0-9a-fA-F]{1,4})$ |
|
Australian Postcode
4 digits
|
^(0[289][0-9]{2}|[1-9][0-9]{3})$ |
|
UK Postcode
Standard format
|
^[A-Z]{1,2}\d[A-Z\d]? ?\d[A-Z]{2}$ |
|
YouTube Video ID
From any YouTube URL
|
(?:youtube\.com\/(?:[^\/]+\/.+\/|(?:v|e(?:mbed)?)\/|.*[?&]v=)|youtu\.be\/)([^"&?\/\s]{11}) |
|
JWT Token
Three base64 parts
|
^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$ |
|
MongoDB ObjectId
24 hex characters
|
^[0-9a-fA-F]{24}$ |
|
Bitcoin Address
Legacy & SegWit
|
^(bc1|[13])[a-zA-HJ-NP-Z0-9]{25,39}$ |
|
Ethereum Address
0x + 40 hex
|
^0x[a-fA-F0-9]{40}$ |
|
Visa Card
Starts with 4
|
^4[0-9]{12}(?:[0-9]{3})?$ |
|
Mastercard
51-55 or 2221-2720
|
^(?:5[1-5][0-9]{14}|2(?:2[2-9][0-9]{12}|[3-6][0-9]{13}|7[01][0-9]{12}|720[0-9]{12}))$ |
|
American Express
34 or 37
|
^3[47][0-9]{13}$ |
|
CVV / CVC
3 or 4 digits
|
^\d{3,4}$ |
|
IBAN
International bank account
|
^[A-Z]{2}\d{2}[A-Z0-9]{11,30}$ |
|
BIC / SWIFT
Bank identifier
|
^[A-Z]{4}[A-Z]{2}[A-Z0-9]{2}([A-Z0-9]{3})?$ |
|
ISO 8601 DateTime
2024-01-15T14:30:00Z
|
^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})?$ |
|
Unix Timestamp
10 digits
|
^\d{10}$ |
|
Latitude
-90 to 90
|
^[-+]?([1-8]?\d(\.\d+)?|90(\.0+)?)$ |
|
Longitude
-180 to 180
|
^[-+]?(180(\.0+)?|((1[0-7]\d)|([1-9]?\d))(\.\d+)?)$ |
|
Base64 String
Encoded data
|
^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$ |
|
Git Commit Hash
7–40 hex chars
|
^[0-9a-f]{7,40}$ |
|
SemVer
1.2.3 or 1.2.3-beta
|
^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-[\w.-]+)?(?:\+[\w.-]+)?$ |
|
HTML Tag Strip
Remove tags
|
<[^>]+> |
|
Markdown Link
[text](url)
|
\[([^\]]+)\]\(([^)]+)\) |
|
Hashtag
#word
|
#(\w+) |
|
Twitter / X Handle
@username
|
^@?\w{1,15}$ |
|
File Extension
.jpg .png .pdf
|
\.([a-zA-Z0-9]+)$ |
|
CSS Variable
--name
|
--[a-zA-Z0-9-_]+ |
|
RGB Color
rgb(0,0,0)
|
^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)$ |
|
RGBA Color
With alpha
|
^rgba\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(0|1|0?\.\d+)\s*\)$ |
|
Time (24h)
HH:MM
|
^([01]\d|2[0-3]):([0-5]\d)$ |
|
Time (12h)
hh:mm AM/PM
|
^(0?[1-9]|1[0-2]):[0-5]\d\s?(AM|PM|am|pm)$ |
|
Roman Numerals
I to MMMCMXCIX
|
^M{0,3}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})$ |
|
Positive Integer
No leading zeros
|
^[1-9]\d*$ |
|
Decimal Number
Optional decimal
|
^-?\d+(\.\d+)?$ |
|
Alphanumeric
Letters + numbers
|
^[a-zA-Z0-9]+$ |
|
Letters Only
A-Z a-z
|
^[a-zA-Z]+$ |
|
Digits Only
0-9
|
^\d+$ |
|
Duplicate Words
Find repeated words
|
\b(\w+)\s+\1\b |
|
Multiple Spaces
Collapse whitespace
|
\s{2,} |
|
Leading Zeros
00123 → 123
|
^0+(?=\d) |
|
Port Number
1–65535
|
^([1-9]\d{0,3}|[1-5]\d{4}|6[0-4]\d{3}|65[0-4]\d{2}|655[0-2]\d|6553[0-5])$ |
|
Domain Name
example.com
|
^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9]$ |
|
Mac Address
Colon or hyphen
|
^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$ |
|
Percentage
0% – 100%
|
^(100(\.0{1,2})?|[1-9]?\d(\.\d{1,2})?)%$ |
|
SQL Injection Risk
Basic detection
|
(?i)(union|select|insert|update|delete|drop|--|;|or\s+1=1) |
|
XSS Script Tag
Script detection
|
<\s*script\b[^>]*>[\s\S]*?<\s*\/\s*script\s*> |