Named Capture Groups
learn and test named capture groups in regex
By Bikram NathLast updated
Named capture groups label regex submatches with string keys so you access `match.groups.year` instead of `match[2]`. Apply `(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})` to "2026-05-19" and you get `{year: "2026", month: "05", day: "19"}` back. The tool shows the resulting groups object live and compares JavaScript and Python named-group syntax in the same view, which no single engine REPL does.
Try it now — free, instant, no signup
What is Named Capture Groups?
Named capture groups extend standard regex submatches by binding a string label to each group. Where a conventional pattern returns `match[2]` for a month field, `(?<month>\d{2})` gives back `match.groups.month`, self-documenting at the call site. The tool lets you write a pattern and immediately see the named groups object it produces against sample text you paste in, with output shown for JavaScript and Python in parallel.
Most developers reach for regex101 when debugging a pattern, and it is the right choice for flag exploration and step-by-step match highlighting. This tool fills a narrower gap: it surfaces the difference between JavaScript's `(?<name>...)` form, which landed in ECMAScript 2018 via V8 6.0, and Python's `(?P<name>...)` form side-by-side, which regex101 does not present in a diff view. If you already know which engine you are targeting, regex101 wins on depth; if you are writing a cross-language pattern, the side-by-side view saves a round-trip.
The most common gotcha is duplicate group names. JavaScript runtimes before ECMAScript 2025 (Node.js under 22, Chrome under 125) throw a SyntaxError if the same name appears even inside alternation branches. ECMAScript 2025 legalized `(?<x>a)|(?<x>b)` for alternation-only cases. Python's `re` module allowed the same name in alternation since 3.7 but still rejects it outside alternation positions, so the two engines diverge in edge cases most developers do not hit until production.