js 中替換全部字符串

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

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

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

 

 

其中替換特殊字符需要轉義:

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章