js can only be replaced by the first one. How do you replace all of them? the way of RegExp is similar to "(" is there a mistake? is there a more elegant way to write it?
String.prototype.replaceAll = function (FindText, RepText) {
regExp = new RegExp(FindText, "gm");
return this.replace(regExp, RepText);
}
//
var s = "abcdefabcedf(123)";
console.log(s.replaceAll("b", "B")); //
console.log(s.replaceAll("(", "[")); //
/*
Uncaught SyntaxError: Invalid regular expression: /(/: Unterminated group
at new RegExp (<anonymous>)
at String.replaceAll (<anonymous>:2:11)
at <anonymous>:7:15
*/
I always feel that some of the basic language functions of js are painful to use.