getMatch()function

getMatch(str: string, regexp: NamedRegExp<T>): NamedRegExpExecArray<T> | undefined
getMatch(str: string, regexp: TypedRegExp<T>): TypedRegExpExecArray<T> | undefined
getMatch(str: string, regexp: RegExp): RegExpExecArray | undefined
ParamType
strstring
String to match against the regular expression. required
regexpNamedRegExp<T>
Regular expression to match against the string. required
strstring
required
regexpTypedRegExp<T>
Regular expression that matches a specific string format. required
regexpRegExp
required
Return
NamedRegExpExecArray<T> | undefined
The match array, or undefined if the string did not match.
TypedRegExpExecArray<T> | undefined
RegExpExecArray | undefined

Get an optional regular expression match, or undefined if no match could be made.

Examples

getMatch("abc", /b/); // ["b"]