requireMatch()function

requireMatch(str: string, regexp: NamedRegExp<T>): NamedRegExpExecArray<T>
requireMatch(str: string, regexp: TypedRegExp<T>): TypedRegExpExecArray<T>
requireMatch(str: string, regexp: RegExp): RegExpExecArray
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>
The match array.
TypedRegExpExecArray<T>
Regular expression match array whose full match is a specific string format.
RegExpExecArray
Throws
ValueError
If the string did not match the regular expression.

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

Examples

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