RegEx Named Capture Groups
April 26, 2021

Without named capture groups
const re = /(\d{4})-(\d{2})-(\d{2})/;
const match = re.exec('2021-04-26');
console.log(match[1]); // -> 2021
console.log(match[2]); // -> 04
console.log(match[3]); // -> 26With named capture groups
const re = /(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})/;
const match = re.exec('2021-04-26');
console.log(match.groups.year); // -> 2021
console.log(match.groups.month); // -> 04
console.log(match.groups.day); // -> 26
// with destructuring assignment
const { year, month, day } = match.groups;Reference
https://2ality.com/2017/05/regexp-named-capture-groups.html#named-capture-groups