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

/blog/ · field notes from the hunt

Regex guides on the Regex Hunter Blog

Regex guides from the Regex Hunter blog: anchors, character classes, groups, lookarounds and flags explained step by step, with live examples to try.

Showing 1–6 of 8 posts · 16 total

/^key=[^=]*$/

key=valuekey=key=42key=on·key=a=bkeyvaluek=v

Guides

Catastrophic backtracking: why a regex can hang

A 7-character pattern can take seconds on a 30-character input, and hours on a 40-character one. How backtracking works, why nested quantifiers like (a+)+ explode, the outages it caused at Stack Overflow and Cloudflare, and the rewrites that make a pattern safe.

Regex Hunter logoRegex Hunter

/^(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})$/

2026-10-131999-12-312000-01-012026-02-28·26-10-132026/10/132026-1-313-10-2026

Guides

Named groups and non-capturing groups in regex

Parentheses do two jobs: they group and they capture. How non-capturing groups (?:…) group without capturing, how named groups (?<year>…) make captures readable, how to refer back to them with \k<name>, and how Python spells it.

Regex Hunter logoRegex Hunter

/^colou?r$/i

colorColourCOLORcolour·colrcoloursdiscolorkolor

Guides

Regex flags explained: i, g, m, s, u, y and d

What each JavaScript regex flag changes, with live examples: case-insensitive i, global g (and the lastIndex trap), multiline m, dotAll s, unicode u, sticky y and indices d, plus how Python spells the same ideas.

Regex Hunter logoRegex Hunter

/^\d{5}$/

90210100010213960614·9021902100ZIP 9021090210-1234

Guides

Regex anchors: ^, $ and multiline mode explained

^ and $ don't match characters, they match positions. Why a pattern without anchors checks less than you think, what the m flag changes, how Python's $ treats a trailing newline, and when to use \A and \z instead.

Regex Hunter logoRegex Hunter

/^[A-Z][a-z]+$/

ParisLimaOsloRome·parisPARISNew YorkR2D2

Guides

Regex character classes: \d, \w, \s, [a-z] and their traps

Character classes are the most-used part of regex and the easiest to get subtly wrong. What [abc], [a-z], [^…], \d, \w and \s really match, and the traps behind them: [A-z], the stray hyphen, the dot inside brackets, and digits that aren't 0 to 9.

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

Today’s board is live

Read the trick. Now go hunt.

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