如何使用js实现字符串的replaceAll功能?
- 内容介绍
- 文章标签
- 相关推荐
本文共计83个文字,预计阅读时间需要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); }
本文共计83个文字,预计阅读时间需要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); }

