method
RegExpConstructor.escape
string: string
): string;
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.
const re = new RegExp(RegExp.escape("foo.bar"));
re.test("foo.bar"); // true
re.test("foo!bar"); // false