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);

Explanation

Named groups make regexes self-documenting and robust to reordering. In replace you reference them as $<month>.

Further reading

Problem with a question

JavaScript · Senior · question 54

Test yourself

Take the JavaScript · Senior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz