Common Regex Patterns
Browse 40 ready-to-use regular expressions. Each pattern has a live tester, match examples, and copy-ready code for JavaScript, Python, and PHP.
Email Address
^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$ Validates email addresses following the standard format: local-part@domain.tld.
URL
^https?:\/\/(www\.)?[a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([a-zA-Z0-9()@:%_+.~#?&/=-]*)$ Validates HTTP and HTTPS URLs with optional www prefix, domain, and path.
Phone Number (International)
^\+?[1-9]\d{1,14}$ Validates international phone numbers in E.164 format (up to 15 digits with optional + prefix).
Phone Number (US)
^\(?[2-9]\d{2}\)?[-.\s]?\d{3}[-.\s]?\d{4}$ Validates US phone numbers in various formats: (555) 123-4567, 555-123-4567, 5551234567.
Phone Number (EU)
^\+?[1-9][0-9]{0,3}[\s.-]?\(?[0-9]{1,5}\)?[\s.-]?[0-9]{1,5}[\s.-]?[0-9]{1,5}$ Validates common European phone number formats with optional country code, area code, and various separators.
IPv4 Address
^((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)$ Validates IPv4 addresses (four octets from 0-255 separated by dots).
IPv6 Address
^([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$ Validates full IPv6 addresses (eight groups of four hexadecimal digits).
Date (YYYY-MM-DD)
^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$ Validates dates in ISO 8601 format with basic month/day range checking.
Date (DD/MM/YYYY)
^(0[1-9]|[12]\d|3[01])\/(0[1-9]|1[0-2])\/\d{4}$ Validates dates in DD/MM/YYYY format with basic day/month range checking.
Time (HH:MM:SS)
^([01]\d|2[0-3]):[0-5]\d:[0-5]\d$ Validates 24-hour time format with valid ranges.
Hex Color Code
^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$ Validates CSS hex color codes in 3-digit or 6-digit format.
Credit Card Number
^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|3[47][0-9]{13}|6(?:011|5[0-9]{2})[0-9]{12})$ Validates major credit card numbers (Visa, Mastercard, Amex, Discover).
US ZIP Code
^\d{5}(-\d{4})?$ Validates US ZIP codes in 5-digit or ZIP+4 format.
Username
^[a-zA-Z][a-zA-Z0-9_-]{2,19}$ Validates usernames: starts with a letter, 3-20 characters.
Strong Password
^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$ Validates strong passwords: min 8 chars, uppercase, lowercase, digit, special char.
URL Slug
^[a-z0-9]+(-[a-z0-9]+)*$ Validates URL-friendly slugs: lowercase, digits, hyphens only.
HTML Tag
<\/?[a-zA-Z][a-zA-Z0-9]*(?:\s[^>]*)?\/?> Matches HTML tags including opening, closing, and self-closing tags.
Whitespace Trim
^\s+|\s+$ Matches leading and trailing whitespace for trimming.
Digits Only
^\d+$ Validates strings containing only numeric digits.
Alphanumeric Only
^[a-zA-Z0-9]+$ Validates strings containing only letters and numbers.
File Extension
\.[a-zA-Z0-9]{1,10}$ Extracts or validates file extensions.
Domain Name
^([a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}$ Validates domain names with proper label format and TLD.
MAC Address
^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$ Validates MAC addresses in colon or hyphen-separated format.
UUID
^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$ Validates UUIDs (versions 1-5) in standard format.
Markdown Link
\[([^\]]+)\]\(([^)]+)\) Matches Markdown links in [text](url) format.
IBAN Number
^[A-Z]{2}\d{2}[A-Z0-9]{4,30}$ Validates International Bank Account Numbers (IBAN): 2-letter country code, 2 check digits, and up to 30 alphanumeric characters.
US Social Security Number
^(?!000|666|9\d{2})\d{3}-(?!00)\d{2}-(?!0000)\d{4}$ Validates US Social Security Numbers in XXX-XX-XXXX format with basic invalid-range exclusions.
Date (MM/DD/YYYY)
^(0[1-9]|1[0-2])\/(0[1-9]|[12]\d|3[01])\/\d{4}$ Validates dates in US format MM/DD/YYYY with basic month and day range checking.
ISO 8601 Datetime
^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])T([01]\d|2[0-3]):[0-5]\d:[0-5]\d(Z|[+-]([01]\d|2[0-3]):[0-5]\d)?$ Validates ISO 8601 datetime strings like 2024-03-28T15:30:00Z with optional timezone offset.
Semantic Version
^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(-[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*)?(\+[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*)?$ Validates semantic versioning (semver) strings with optional pre-release and build metadata.
JWT Token
^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$ Validates JSON Web Token format: three Base64url-encoded segments separated by dots.
Base64 String
^[A-Za-z0-9+/]+(={0,2})$ Validates standard Base64-encoded strings with optional padding.
CSS Color Value
^(#([0-9a-fA-F]{3}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})|rgba?\(\s*\d{1,3}\s*,\s*\d{1,3}\s*,\s*\d{1,3}(\s*,\s*(0|1|0?\.\d+))?\s*\)|hsla?\(\s*\d{1,3}\s*,\s*\d{1,3}%\s*,\s*\d{1,3}%(\s*,\s*(0|1|0?\.\d+))?\s*\))$ Matches CSS color values including hex (#RGB, #RRGGBB, #RRGGBBAA), rgb(), rgba(), hsl(), and hsla() functions.
JSON String Literal
^"([^"\\]|\\.)*"$ Matches a JSON-style double-quoted string with proper escape sequence handling.
HTML Entity
&(#[0-9]+|#x[0-9a-fA-F]+|[a-zA-Z][a-zA-Z0-9]*); Matches HTML entities: named (&), decimal ({), and hexadecimal (😀) forms.
Cron Expression
^(\*|[0-5]?\d)(\/\d+)?(\s+(\*|[01]?\d|2[0-3])(\/\d+)?)(\s+(\*|[0-3]?\d)(\/\d+)?)(\s+(\*|[01]?\d|1[0-2])(\/\d+)?)(\s+(\*|[0-7])(\/\d+)?)$ Validates standard 5-field cron expressions (minute, hour, day-of-month, month, day-of-week).
Docker Image Tag
^([a-z0-9]+([._-][a-z0-9]+)*(\/[a-z0-9]+([._-][a-z0-9]+)*)*)(:([a-zA-Z0-9][a-zA-Z0-9._-]{0,127}))?$ Validates Docker image references with optional registry, namespace, and tag.
S3 Bucket Name
^(?!.*\.\.)(?!.*-\.)(?!.*\.-)(?!xn--)(?!sthree-)(?!sthree-configurator)[a-z0-9][a-z0-9.-]{1,61}[a-z0-9]$ Validates AWS S3 bucket names: 3-63 characters, lowercase alphanumeric with dots and hyphens, no adjacent periods or mixed separators.
AWS ARN
^arn:(aws|aws-cn|aws-us-gov):[a-zA-Z0-9_-]+:[a-z0-9-]*:\d{0,12}:.+$ Validates AWS Amazon Resource Names in arn:partition:service:region:account-id:resource format.
Environment Variable Name
^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$ Validates UPPER_SNAKE_CASE environment variable names starting with a letter.
Test your own pattern
Use the Regex Tester to build and debug custom expressions in real time.