escapeRegExp
function escapeRegExp(value: string): string;
Put user input through this before building a RegExp from it, and a dot stays a dot instead of matching any character.
Parameters
Parameter | Type | Description |
|---|---|---|
|
| The string to escape. It must not be empty. |
Returns
string — the escaped string, safe to drop into a pattern.
Throws
Exception | Condition |
|---|---|
| the value is not a string, or is empty. |
Examples
Escaping
escapeRegExp("a.b*c"); // => "a\\.b\\*c"
new RegExp(escapeRegExp("1.5")).test("1x5"); // => false
See also
Source
23 September 2026
This documentation was generated with AI (Claude) from the library's source code.