freecoding.school100% FREE · NO SIGNUP
Closure CavesISSUE #33 of 61

regex · groups · capture · backreference

LambdaVSThe Mutator
Lambda saysGroups capture parts of a match; named groups label them for clarity.

Parentheses (…) capture a sub-match you can reference in the result or in a replacement ($1). Named groups (?<year>\d{4}) read out as match.groups.year — far clearer than numbered ones. Non-capturing groups (?:…) group without capturing.

Power-ups you unlock

The Mutator attacks — common mistakes

Boss battleParse a date string into named year/month/day groups.

Example code

<!doctype html><html><head><meta charset="utf-8"></head>
<body style="background:#06040d;color:#e6e0ff;font-family:monospace;padding:20px"><pre id="o"></pre>
<script>const m='2026-05-28'.match(/(?<y>\d{4})-(?<mo>\d{2})-(?<d>\d{2})/);
document.getElementById('o').textContent=JSON.stringify(m.groups);</script></body></html>
▶ Open the interactive comic issue
‹ Regex · Flags · G · I · M · S · U · YRegex · Lookahead · Lookbehind ›