var str = "aaa的大收拾收拾的大收拾收拾得到的淡淡的洒事实上";
var sub = '的';
var rep = 'new';
var newStr;
var reg = new RegExp(sub,"g");
console.log(str.replace(reg,rep))
function getNewStr(originStr,subStr,replacement){
newStr = originStr.replace(subStr,replacement);
if(newStr.match(subStr)){
getNewStr(newStr,subStr,replacement);
}
console.log(14)
return newStr
}
var objStr = getNewStr(str,sub,rep);
console.log(objStr)
转载于:https://www.cnblogs.com/lcddjm/p/6423331.html