Regex Pattern Library
47 tested regex patterns for email, phone, URL, password, UUID, date, credit card, and more. Each page has copy-paste code for JavaScript, Python, Ruby, PHP, and Java.
Quick Answer
Regex (regular expressions) define patterns for matching text. Common uses: validating email, phone numbers, URLs, passwords; extracting data; find-and-replace. Most languages use PCRE-compatible syntax with minor differences in flags and escaping. Click any pattern below for tested examples and copy-paste code in 5 languages.
Common Validation
Email Address
Validates a standard email address format
^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA...Email (RFC 5322 Compliant)
RFC 5322 compliant email validation with label length limits
^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-...URL (HTTP/HTTPS)
Validates HTTP and HTTPS URLs
^https?:\/\/(?:[\w-]+\.)+[a-zA-Z]{2,}(?:...URL (Any Protocol)
Matches URLs with any protocol (http, https, ftp, ws, etc.)
^(?:[a-zA-Z][a-zA-Z0-9+.-]*:\/\/)[^\s/$....Domain Name
Validates a domain name (no protocol)
^(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-z...Phone Numbers
US Phone Number
US phone number in common formats
^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?(...International Phone (E.164)
Validates E.164 international format — + followed by 2-15 digits
^\+[1-9]\d{1,14}$Indian Phone Number
Indian mobile number with optional +91 country code
^(?:\+91[- ]?)?[6-9]\d{9}$UK Phone Number
UK mobile number with optional +44 country code
^(?:\+44|0)7\d{9}$Passwords
Networking
IPv4 Address
Validates a well-formed IPv4 address (0-255 in each octet)
^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)...IPv6 Address
Basic IPv6 address (8 groups of 4 hex digits)
^([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$MAC Address
MAC address with colons or dashes as separators
^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})...Payment
Visa Credit Card
Visa card — starts with 4, 13 or 16 digits total
^4[0-9]{12}(?:[0-9]{3})?$Mastercard Credit Card
Mastercard — 16 digits starting with 51-55 or 2221-2720
^(?:5[1-5][0-9]{14}|2(?:2(?:2[1-9]|[3-9]...American Express Card
Amex — 15 digits starting with 34 or 37
^3[47][0-9]{13}$Any Credit Card
Visa, Mastercard, Amex, Discover, Diners
^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{...Identifiers
UUID v4
UUID version 4 (randomly generated)
^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[8...UUID (Any Version)
Any RFC 4122 UUID (versions 1-5)
^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3...JWT Token
JSON Web Token (header.payload.signature)
^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z...Hex String
Any-length hexadecimal string
^[0-9a-fA-F]+$Base64 String
Standard base64 encoded string
^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2...Alphanumeric Username
Username with letters, digits, underscores (3-16 chars)
^[a-zA-Z0-9_]{3,16}$Twitter Handle
Twitter/X handle, 1-15 chars, optional @
^@?(\w){1,15}$URL Slug
Lowercase URL-friendly slug with dashes
^[a-z0-9]+(?:-[a-z0-9]+)*$Date & Time
Date YYYY-MM-DD
ISO 8601 date format
^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[...Date DD/MM/YYYY
European date format with slashes
^(0[1-9]|[12]\d|3[01])\/(0[1-9]|1[0-2])\...24-Hour Time
24-hour clock time in HH:MM format
^([01]\d|2[0-3]):([0-5]\d)$12-Hour Time with AM/PM
12-hour clock with AM/PM
^(0?[1-9]|1[0-2]):([0-5]\d)\s?(AM|PM|am|...Postal Codes
Numbers
Positive Integer
Integers greater than zero (no leading zeros)
^[1-9]\d*$Non-negative Integer
Zero or positive integer
^(0|[1-9]\d*)$Decimal Number
Optionally signed decimal number
^-?\d+(?:\.\d+)?$Hex Color Code
3 or 6-digit hex color with optional #
^#?([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$USD Currency
US dollar amount with optional $ and thousands separators
^\$?\d{1,3}(,\d{3})*(\.\d{2})?$File Paths
File Extension
File extension at the end of a filename
\.[a-zA-Z0-9]+$Image File Extension
Common image file extensions
\.(jpg|jpeg|png|gif|bmp|webp|svg|avif|he...Video File Extension
Common video file extensions
\.(mp4|mov|avi|mkv|webm|flv|wmv|m4v)$Absolute Unix Path
Absolute filesystem path starting with /
^\/(?:[^\/\0]+\/)*[^\/\0]*$