Escapes any potential regex syntax characters in a string, and returns a new string that can be safely used as a literal pattern for the RegExp() constructor.
interface
RegExpConstructor
interface RegExpConstructor
- constructor RegExpConstructor(pattern: string | RegExp): RegExp;constructor RegExpConstructor(pattern: string,flags?: string): RegExp;constructor RegExpConstructor(pattern: string | RegExp,flags?: string): RegExp;
const re = new RegExp(RegExp.escape("foo.bar")); re.test("foo.bar"); // true re.test("foo!bar"); // false