Named Capturing Groups
RX · Groups & Alternationsyntax
JS: (?<name>pattern) Python: (?P<name>pattern)example
JS: const m = '2026-04-04'.match(/(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})/)
m.groups.year // "2026"
Py: m = re.search(r'(?P<year>\d{4})-(?P<month>\d{2})-(?P<day>\d{2})', '2026-04-04')
m.group('year') # '2026'output
JS: m.groups => { year: "2026", month: "04", day: "04" }
Py: m.group('year') => '2026'Note Syntax differs between JS and Python. JS uses (?<name>...) while Python uses (?P<name>...). Named groups dramatically improve readability of complex patterns. Both approaches also assign a numeric index.