如何将JavaScript中的replaceAll方法改写为长尾词?
- 内容介绍
- 文章标签
- 相关推荐
本文共计82个文字,预计阅读时间需要1分钟。
使用正则表达式替换字符串中的所有匹配项,可以使用以下代码:
javascriptString.prototype.replaceAll=function(s1, s2) { return this.replace(new RegExp(s1, gm), s2);};
使用正则表达式替换字符串中的所有匹配项String.prototype.replaceAll = function(s1,s2){ return this.replace(new RegExp(s1,"gm"),s2); }
本文共计82个文字,预计阅读时间需要1分钟。
使用正则表达式替换字符串中的所有匹配项,可以使用以下代码:
javascriptString.prototype.replaceAll=function(s1, s2) { return this.replace(new RegExp(s1, gm), s2);};
使用正则表达式替换字符串中的所有匹配项String.prototype.replaceAll = function(s1,s2){ return this.replace(new RegExp(s1,"gm"),s2); }

