Introduction
This was introduced in ES2018
Proposal
RegExp Named Capture Groups1
Syntax
Indexed entries
Named capture groups also created indexed entries, like numbered
capture
groups
Destructuring
Destructuring works well with
this:
Backreferences
\k<name>
matches the string that was previously matched by the named
capture group name
:
Backreference syntax for numbered capture
groups works
as well:
Both can be mixed:
repalce() and named capture groups
replace() supports
named capture groups in two ways:
Mention names in replacement string
Each replacement function receives an additional parameter that holds an object with data captured via named groups
Rest parameters can also be used to
access the last argument:
See also