bhylu.com

Advertisements

JS RegExp Groups

Groups capture parts of a match. Named groups can make the result easier to read.

Where to run this

This example uses the JavaScript console playground. Select Run to execute it; the example does not run on this lesson page.

A practical example

JavaScript

const match = /^(?<day>Sat)-(?<count>\d+)$/.exec("Sat-12");
console.log(match.groups.day, match.groups.count);

What happens

The captured values are Sat and the string 12.