📜  replaceAll 替换字符串值 javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:42.154000             🧑  作者: Mango

代码示例1
function replaceAll(str, find, replace) {
    var escapedFind=find.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
    return str.replace(new RegExp(escapedFind, 'g'), replace);
}
//usage example
var sentence="How many shots did Bill take last night? That Bill is so crazy!";
var blameSusan=replaceAll(sentence,"Bill","Susan");