Escapes a string to be used in a regular expression. From: https://stackoverflow.com/a/3561711
const badName = "([{^|";const regex = new RegExp(`^(maciek|${escapeRegExp(badName)})$`); // won't crashregex.test(badName); // true Copy
const badName = "([{^|";const regex = new RegExp(`^(maciek|${escapeRegExp(badName)})$`); // won't crashregex.test(badName); // true
string to escape
Escapes a string to be used in a regular expression. From: https://stackoverflow.com/a/3561711
Example