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

/blog/ · field notes from the hunt

The Regex Hunter Blog

Guides, regex strategy and cheat sheets from Regex Hunter: practical articles on writing patterns that catch every target and spare the rest, with live examples.

Showing 7–12 of 16 posts · 16 total

/^(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

/<.+?>/

<b></i><br>·bi><>

Guides

Greedy vs lazy quantifiers: why .* eats too much

Regex quantifiers grab as much text as they can. Here's how greedy and lazy matching really work, why <.+> swallows a whole line of HTML, and when a negated class beats both.

Regex Hunter logoRegex Hunter

/(.)\1/

booklettercoffee·catdoglemon

Guides

Regex backreferences: patterns that remember what they matched

A backreference like \1 matches the exact text a group already captured. Here's how they work, how to find doubled letters, repeated words and palindromes, and the one place they don't work.

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.