When running my replace statement using a regular expression not defined by the regex object it returns the correct result
var str = "from |cffa22fc8Peachee|r others";
var res = str.replace(/\|cffa22fc8Peachee\|r/gi, "red");
console.log(res);
//> from red others
However when it is executed using the regex object (which i need to be able to use) The result is different, even though i escaped the special characters.
var str = "from |cffa22fc8Peachee|r others";
var regex = new RegExp("/\|cffa22fc8Peachee\|r/", "gi");
var res = str.replace(regex, "red");
console.log(res)
//> from |red|r others