Regex Pattern Library

Browse and copy 41+ common regular expression patterns. Click Test to try a pattern inline.

Showing 41 of 41 patterns

Email AddressValidation
/^[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}$/

Validates a standard email address format.

Example:user@example.com
URL (http/https)Validation
/^https?:\/\/[^\s/$.?#].[^\s]*$/i

Matches http or https URLs.

Example:https://example.com/path?q=1
IPv4 AddressValidation
/^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$/

Validates a dotted-decimal IPv4 address (0–255 per octet).

Example:192.168.1.255
IPv6 AddressValidation
/^([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}:){1,7}:$|^([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}$/

Validates a full or compressed IPv6 address.

Example:2001:0db8:85a3:0000:0000:8a2e:0370:7334
Phone (US)Validation
/^\+?1?\s?\(?\d{3}\)?[\s.\-]?\d{3}[\s.\-]?\d{4}$/

Matches US phone numbers in common formats.

Example:+1 (555) 867-5309
Phone (International)Validation
/^\+[1-9]\d{1,14}$/

E.164 international phone number format.

Example:+447911123456
ZIP Code (US)Validation
/^\d{5}(-\d{4})?$/

Matches 5-digit US ZIP codes with optional +4 extension.

Example:90210-1234
Postal Code (Canada)Validation
/^[A-Z]\d[A-Z]\s?\d[A-Z]\d$/i

Matches Canadian postal codes (e.g. A1B 2C3).

Example:K1A 0B1
Credit Card (Generic)Validation
/^\d{4}[\s\-]?\d{4}[\s\-]?\d{4}[\s\-]?\d{4}$/

Matches 16-digit card numbers with optional spaces or hyphens.

Example:4111 1111 1111 1111
SSN (US)Validation
/^\d{3}-\d{2}-\d{4}$/

Matches US Social Security Numbers in dashed format.

Example:123-45-6789
IBANValidation
/^[A-Z]{2}\d{2}[A-Z0-9]{4}\d{7}([A-Z0-9]?){0,16}$/

International Bank Account Number format.

Example:GB82WEST12345698765432
ISO 8601 DateDate/Time
/^\d{4}-\d{2}-\d{2}$/

Matches dates in YYYY-MM-DD format.

Example:2024-03-15
US Date (MM/DD/YYYY)Date/Time
/^(0?[1-9]|1[0-2])\/(0?[1-9]|[12]\d|3[01])\/\d{4}$/

Matches US-style dates with month and day validation.

Example:03/15/2024
Time (24-hour)Date/Time
/^([01]?\d|2[0-3]):[0-5]\d(:[0-5]\d)?$/

Matches 24-hour time with optional seconds.

Example:23:59:59
Time (12-hour)Date/Time
/^(0?[1-9]|1[0-2]):[0-5]\d\s?(AM|PM|am|pm)$/

Matches 12-hour time with AM/PM.

Example:11:59 PM
Strong PasswordPassword
/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/

Requires uppercase, lowercase, digit, and special character; min 8 chars.

Example:Passw0rd!
Alphanumeric OnlyPassword
/^[a-zA-Z0-9]+$/

Allows only letters and digits, no spaces or symbols.

Example:abc123XYZ
Letters OnlyPassword
/^[a-zA-Z]+$/

Allows only alphabetic characters (a-z, A-Z).

Example:HelloWorld
Numbers OnlyPassword
/^\d+$/

Allows only numeric digits (0-9).

Example:0123456789
HTML TagWeb
/<([a-z]+)([^<]+)*(?:>(.*?)<\/\1>|\s+\/>)/i

Matches HTML opening/closing tag pairs or self-closing tags.

Example:<div class="foo">bar</div>
HTML CommentWeb
/<!--[\s\S]*?-->/

Matches HTML comments including multiline.

Example:<!-- This is a comment -->
CSS Hex ColorWeb
/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/

Matches 3 or 6 digit CSS hex color codes.

Example:#ff6600
CSS rgb()Web
/^rgb\(\s*\d{1,3}\s*,\s*\d{1,3}\s*,\s*\d{1,3}\s*\)$/

Matches CSS rgb() color function with 0-999 values (use with range check).

Example:rgb(255, 128, 0)
URL SlugWeb
/^[a-z0-9]+(?:-[a-z0-9]+)*$/

Validates URL slugs: lowercase alphanumeric with single hyphens.

Example:my-blog-post
UUIDWeb
/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i

Matches UUIDs in standard 8-4-4-4-12 hex format.

Example:550e8400-e29b-41d4-a716-446655440000
MD5 HashWeb
/^[a-f0-9]{32}$/i

Matches a 32-character hexadecimal MD5 hash.

Example:d41d8cd98f00b204e9800998ecf8427e
SHA-256 HashWeb
/^[a-f0-9]{64}$/i

Matches a 64-character hexadecimal SHA-256 hash.

Example:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
Base64Web
/^[A-Za-z0-9+\/]*(={0,2})?$/

Matches Base64 encoded strings with optional padding.

Example:SGVsbG8gV29ybGQ=
JWT TokenWeb
/^[A-Za-z0-9\-_]+\.[A-Za-z0-9\-_]+\.[A-Za-z0-9\-_]+$/

Matches JSON Web Tokens (three base64url segments).

Example:eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1c2VyIn0.abc123
Semantic VersionWeb
/^\d+\.\d+\.\d+(-[a-zA-Z0-9.]+)?(\+[a-zA-Z0-9.]+)?$/

Matches semver strings with optional pre-release and build metadata.

Example:1.2.3-beta.1+build.42
GitHub URLWeb
/^https?:\/\/github\.com\/[a-zA-Z0-9\-\.]+\/[a-zA-Z0-9\-\.]+/

Matches GitHub repository URLs.

Example:https://github.com/user/my-repo
VISA CardIdentifiers
/^4[0-9]{12}(?:[0-9]{3})?$/

Matches VISA card numbers (13 or 16 digits starting with 4).

Example:4111111111111111
MasterCardIdentifiers
/^5[1-5][0-9]{14}$/

Matches MasterCard numbers (16 digits, starting with 51-55).

Example:5500005555555559
American ExpressIdentifiers
/^3[47][0-9]{13}$/

Matches Amex 15-digit card numbers starting with 34 or 37.

Example:371449635398431
Driver's License (US Generic)Identifiers
/^[A-Z0-9]{7,9}$/i

Generic 7-9 character alphanumeric US driver license number.

Example:D1234567
Whitespace OnlyText
/^\s+$/

Matches strings that contain only whitespace characters.

Example:
Empty StringText
/^$/

Matches an empty string (zero characters).

Positive IntegerText
/^\d+$/

Matches non-negative whole numbers (0, 1, 2, ...).

Example:42
Negative IntegerText
/^-\d+$/

Matches negative whole numbers (-1, -2, ...).

Example:-7
Decimal Number (Float)Text
/^-?\d+\.\d+$/

Matches positive or negative decimal numbers.

Example:-3.14
Scientific NotationText
/^-?\d+(\.\d+)?[eE][+\-]?\d+$/

Matches numbers in scientific notation.

Example:6.022e+23