Common Regex Patterns: Email, URL, Phone & More

Some patterns come up again and again. Here are practical, real-world regexes you can adapt — and a reminder that "perfect" patterns often aren't worth it.

Email (practical)

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

This catches the vast majority of real addresses. Fully RFC-compliant email regexes are enormous and rarely worth it — for real validation, send a confirmation email.

URL

^https?://[^\s/$.?#].[^\s]*$

Matches http/https URLs. Adjust if you need to allow other schemes.

Phone number (flexible)

^\+?[\d\s()-]{7,15}$

Allows an optional +, digits, spaces, parentheses, and dashes. Phone formats vary wildly by country, so keep it loose.

IPv4 address

^(\d{1,3}\.){3}\d{1,3}$

A quick shape check. For strict 0–255 range validation, the pattern gets much longer.

Hex color

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

Matches #fff and #ffffff, with or without the #.

Slug (URL-friendly string)

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

Lowercase letters, numbers, and single dashes — like my-blog-post.

A word of caution

Regex is great for shape checks, but for semantics (does this email exist? is this date real?) use proper validation or libraries. See the regex cheat sheet for the syntax basics.

Test them

Paste any of these into the regex tester and try them against your own sample text.

Got a config file to check?

Open the config toolkit →