In this example:
let name = "dea+hl[]rd";
let text = "This dea+hl[]rd guy is super annoying.";
let escaped = name.replace(/[\\\[.+*?(){|^$]/g, "\\$&");
let regexp = new RegExp("\\b" + escaped + "\\b", "gi");
console.log(text.replace(regexp, "_$&_"));
// → This _dea+hl[]rd_ guy is super annoying.
Do you need that 3rd backslash at the beginning?
/[\\\[.+*?(){|^$]/g
https://scrn.es/WU5OBMAXhGTQHmYR6BuVi
vs.
/[\\[.+*?(){|^$]/g
https://scrn.es/4GiJj6ScfTCD22kmrLY1Dh
If i'm following, the first two represent an escaped backslash. Which means the 3rd one is escaping the open bracket. But do you need to do that here?
In this example:
Do you need that 3rd backslash at the beginning?
/[\\\[.+*?(){|^$]/ghttps://scrn.es/WU5OBMAXhGTQHmYR6BuVi
vs.
/[\\[.+*?(){|^$]/ghttps://scrn.es/4GiJj6ScfTCD22kmrLY1Dh
If i'm following, the first two represent an escaped backslash. Which means the 3rd one is escaping the open bracket. But do you need to do that here?