代码:str.replace(/word/g,"Excel");
另外一种写法:str.replace(new RegExp("word","gm"),"Excel");
注意:当替换特殊字符时,如?字符串 ,str.replace(new RegExp("word","gm"),"Excel");这种形式,word替换为://?。
str.replace(/word/g,"Excel");这种形式,word替换为/?即可
参考链接:http://www.jb51.net/article/54173.htm