Create a named group in a JavaScript RegExp
Published on
To create a named group in a JavaScript RegExp, we can use the (?<name>...)
syntax:
ts
consttext = 'foo bar foo'constregex = /(?<wanted>bar)/constresult =regex .exec (text )if (result === null) {throw newError ('No match')}constwantedGroup =result .groups ?.wanted