直接上函数吧 不废话
function replacestring(oldstr,newstr,text){ var exp = new RegExp(oldstr,'g'); var c=text.replace(exp,newstr); return c;} var oldstr='world';var newstr='cccc';var text='Hello world, Hello world';var aa= replacestring(oldstr,newstr,text); console.log(aa);
posted on 2019-08-10 11:07 阅读( ...) 评论( ...) 收藏