getMatchGroups()function

getMatchGroups(str: string, regexp: NamedRegExp<T>): T | undefined
getMatchGroups(str: string, regexp: RegExp): NamedRegExpData | undefined
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 | undefined
The set of named match groups, or undefined if the string did not match.
NamedRegExpData | undefined

Get the named groups of an optional regular expression match, or undefined if no match could be made.

Examples

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