js replace

替换单个字符串:

1 var str="Visit Microsoft!"
2 console.log(str.replace(/Microsoft/,"W3School"));

 

替换多个字符串:

1 var str="Welcome to Microsoft! ";
2 str=str + "We are proud to announce that Microsoft has ";
3 str=str + "one of the largest Web Developers sites in the world.";
4 console.log(str.replace(/Microsoft/g, "W3School"))

 

替换转义字符:

1 var str="Welcome to "Microsoft"! ";
2 str=str + "We are proud to announce that "Microsoft" has ";
3 str=str + "one of the largest Web Developers sites in the world.";
4 console.log(str.replace(/Microsoft/g, "W3School"))
5 console.log(str.replace(new RegExp('"',"gm"),'"'))

 

参考地址:

https://www.w3school.com.cn/jsref/jsref_replace.asp

posted @ 2022-01-27 15:01  啄木鸟伍迪  阅读(331)  评论(0)    收藏  举报
//火箭 GenerateContentList();