Js string replaces all

The replace of

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.

Mar.04,2021

replaces all, that is, the regular expression is marked with global g . For "and' are \" and\'


.

that's fine, but I don't know what the efficiency is:

String.prototype.replaceAll = function (FindText, RepText) { 
    return this.split(FindText).join(RepText); 
}
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3b2ad-2b5d5.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3b2ad-2b5d5.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?