var a="hello world ! 你好,世界!hello world!";

a.replace(/你好,世界/g,'我是谁');   //"hello world ! 我是谁!hello world!"

a.replace(/hello/g,'你好'); //"你好 world ! 你好,世界!你好 world!"

 

 

其中替换特殊字符需要转义:

js 中替换全部字符串

相关文章: