JavaScript · Senior · Question 54 of 75
What does this regex give you?
const { groups } = /(?<year>\d{4})-(?<month>\d{2})/.exec("2025-07");
console.log(groups.month);- ✓Correct answer:
"07"- named capture groups are available by name - 2
"2025" - 3It throws, named groups aren't supported
Explanation
Named groups make regexes self-documenting and robust to reordering. In replace you reference them as $<month>.