本页面有中文版。
Cette page est disponible en français.
Esta página está disponible en español.

/blog/ · field notes from the hunt

Regex patterns on the Regex Hunter Blog

Ready-to-use regex patterns explained: emails, URLs, dates, phone numbers, IP addresses and more, each with the edge cases it catches and the ones it misses.

Showing 1–5 of 5 posts · 16 total

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

Secret123aB3defghTr0ub4dor9Lives_cat·secret123SECRET123SecretpassAb1

Patterns

Password rules with regex lookaheads (and when not to)

How to check \"at least one uppercase letter, one digit, eight characters\" in a single regex with lookaheads, why the order-free version needs them, the traps in the common patterns, and why checking each rule separately is often the better design.

Regex Hunter logoRegex Hunter

/^(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)$/

042199255·256300071000

Patterns

Regex for IPv4 addresses: matching 0 to 255 properly

An IPv4 address is four numbers from 0 to 255. Here's why the obvious \d{1,3} pattern lets 999.999.999.999 through, how to match one octet with alternation, what to do about leading zeros, and how to find addresses inside text.

Regex Hunter logoRegex Hunter

/^https?://\S+$/

https://a.iohttp://x.com/phttps://b.dev?q=1·ftp://x.comwww.x.comhttp:/x.com

Patterns

Regex for URLs: what to match and what to leave to a parser

Finding links in text and validating a URL are different jobs. Here's a pattern for each, the traps that let bad URLs through (trailing punctuation, unescaped dots, missing anchors), and when to hand the work to new URL() or urllib.

Regex Hunter logoRegex Hunter

/^\d{3}[-. ]?\d{3}[-. ]?\d{4}$/

555-123-4567555.123.45675551234567·555-123455-123-4567555-123-456

Patterns

Regex for phone numbers: US formats, E.164, and when to stop

People type the same phone number a dozen ways. Here's how to match US numbers with dashes, dots, spaces, parentheses and an optional +1, how to check the international E.164 format, and why real validation needs a library.

Regex Hunter logoRegex Hunter

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

ana@site.comx+t@site.iojo@mail.co.uk·ana@example@site.coma@@b.io

Patterns

Email regex: copy-ready patterns that actually work

Three copy-ready email regex patterns (simple, practical and strict), when to use each, and the common mistakes that reject real addresses.

Regex Hunter logoRegex Hunter

Today’s board is live

Read the trick. Now go hunt.

Match every monster, spare every innocent — in as few characters as you can.