Regex Patterns Library

Copy-paste common regex patterns for email, phone, dates, URLs, and more

๐Ÿ“‹ Pattern Library

Email Address

^[^\s@]+@[^\s@]+\.[^\s@]+$

Matches simple email format

URL (HTTP/HTTPS)

^https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)$

Matches HTTP and HTTPS URLs

Phone Number (US)

^(\+1[-.]?)?\(?\d{3}\)?[-.]?\d{3}[-.]?\d{4}$

Matches US phone numbers with various formats

Date (YYYY-MM-DD)

^\d{4}-\d{2}-\d{2}$

Matches ISO 8601 date format

Time (HH:MM:SS)

^([01]?[0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]$

Matches 24-hour time format

Hexadecimal Color

^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$

Matches hex color codes (#RRGGBB or #RGB)

IP Address (IPv4)

^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$

Matches IPv4 addresses (0.0.0.0 - 255.255.255.255)

Credit Card

^\d{4}[\s-]?\d{4}[\s-]?\d{4}[\s-]?\d{4}$

Matches 16-digit credit card numbers

Username (alphanumeric + underscore)

^[a-zA-Z0-9_]{3,20}$

Matches usernames 3-20 chars, letters/numbers/underscore only

Slug (URL-friendly)

^[a-z0-9]+(?:-[a-z0-9]+)*$

Matches URL slugs (lowercase, hyphens, no spaces)

Hashtag

^#[a-zA-Z0-9_]{1,30}$

Matches Twitter/social hashtags

Whitespace Only

^\s*$

Matches empty string or whitespace only

๐Ÿงช Test Your Pattern