Named Capture Groups
learn and test named capture groups in regex
Interactive Named Capture Groups — coming soon
In development. We're still building the interactive Named Capture Groups. The guide below explains exactly what it does and how to use it. In the meantime, here are DevLab tools that already work in your browser:
Browse all working tools →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.
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.
When to use Named Capture Groups
- Migrate a numbered-group pattern to named groups so teammates can read extracted fields without counting parentheses.
- Verify that a shared regex pattern compiles and extracts correctly under both JavaScript and Python before committing.
- Debug a log parser returning wrong fields after the log format gains a column and shifts every positional index.
Frequently Asked Questions
Does Python use different named-group syntax than JavaScript?
Can I reference a named group inside the replacement string?
What actually happens when the same group name appears twice in one pattern?
Why does `match.groups` return `undefined` even though my pattern compiles fine?
Can named capture groups be defined inside a lookahead or lookbehind?
Related Tools
- Regex Testertest and debug regular expressions with real-time matching · Regex
- Regex Explainerbreak down a regex pattern into plain English with visual diagrams · Regex
- Lookahead & Lookbehind Guidelearn lookahead and lookbehind assertions with interactive examples · Regex
- Regex Cheatsheetbrowse a complete regex syntax reference with live examples · Regex