requireMatchGroups()function

requireMatchGroups(str: string, regexp: NamedRegExp<T>): T
requireMatchGroups(str: string, regexp: RegExp): NamedRegExpData
ParamType
strstring
String to match against the regular expression. required
regexpNamedRegExp<T>
Regular expression to match against the string. required
strstring
required
regexpRegExp
required
Return
T
The set of named match groups.
NamedRegExpData
Set of named match groups from a regular expression.
Throws
ValueError
If the string did not match the regular expression.

Get the named groups of a required regular expression match, or throw ValueError if no match could be made.

Examples

requireMatchGroups("abc", /(?<first>a)/); // { first: "a" }