Common Regex Patterns You'll Actually Use (Copy-Paste Ready)

Nobody memorizes regex. You look up the same six or seven patterns over and over, copy one, and move on. Here they are in one place, with a plain-English breakdown of what each part is doing — so you're not just pasting a black box.

Email address

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

This covers the vast majority of real-world email addresses. Worth knowing: the full official email spec (RFC 5322) is far too complex to fully validate with regex — no pattern, including this one, guarantees an address is real or deliverable. Use regex for client-side UX (catching obvious typos before someone hits submit), not as your only line of defense. The only way to actually confirm an email is real is to send a confirmation link to it.

URL

^https?:\/\/[\w.-]+\.[a-z]{2,}(\/\S*)?$

Matches http:// or https://, a domain, and an optional path. Good enough for form validation; if you need to handle every edge case of the URL spec (ports, query strings, IPv6 hosts), reach for a proper URL-parsing library instead.

Phone number (US-style)

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

Matches (555) 123-4567, 555-123-4567, 555.123.4567, and 5551234567. International numbers vary too much in format for a single regex to handle reliably — for anything beyond a single country, a dedicated phone-validation library will save you a lot of pain.

Strong password check

^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[\W_]).{8,}$

Uses lookaheads (?=...) to require at least one lowercase letter, one uppercase letter, one digit, and one symbol, with a minimum length of 8. Worth noting: character-class requirements like this are actually weaker guidance than pure length — a random 16-character string beats an 8-character one with a symbol crammed in, every time.

Extract hashtags or mentions

[#@]\w+

Grabs anything starting with # or @ followed by word characters — handy for parsing social text.

HEX color code

^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$

Matches both 6-digit (#a855f7) and shorthand 3-digit (#a5f) hex colors.

Test any of these instantly

Paste a pattern and some sample text into the Regex Tester to see live match highlighting before you commit it to your code — much faster than debugging a regex by trial and error in your actual application.