toRegExp
The toRegExp() function normalizes a string, string array, or RegExp into a regular expression. When the input is textual, it escapes regex metacharacters and builds an exact-match pattern.
Interactive example
Syntax
typescript
function toRegExp(
input: string | string[] | RegExp
): RegExp;Parameters
input: Value to convert into aRegExp.
Return value
A RegExp:
- from a
string: exact literal match (^...$) - from a
string[]: exact alternatives (^(?:...|...)$) - from a
RegExp: the same instance
See also
escapeRegExp- Escapes special characters for regex usage
