JavaScript中替换所有replaceAll
2017-12-07 22:40
393 查看
js居然不提供replaceAll方法,用for循环又有效率问题,给你一个正则表达式的解决方案
String.prototype.replaceAll = function(s1,s2) {
return
this.replace(new RegExp(s1,"gm"),s2);
};
gm
g=global, m=multiLine , 大致上方法就是这样的,可以实现替换全部指定字串
String.prototype.replaceAll = function(s1,s2) {
return
this.replace(new RegExp(s1,"gm"),s2);
};
gm
g=global, m=multiLine , 大致上方法就是这样的,可以实现替换全部指定字串
相关文章推荐
- javascript replaceAll js替换重复处理
- preg_match_all结合str_replace替换内容中所有img
- preg_match_all结合str_replace替换内容中所有img
- javascript使用replace替换字符串中所有字符
- js字符串替换 - 无replaceAll替换所有字符串的解决方案
- php preg_match_all结合str_replace替换内容中所有img
- Replace All Matches Between the Matches of Another (替换所有在匹配间的匹配)
- Javascript中使用replace()方法+正则表达式替换掉所有字符
- JavaScript 中的replace方法(全部替换replaceAll效果)
- javascript 实现全部替换(replaceAll)
- JavaScript中的replace()方法替换所有匹配项
- preg_match_all结合str_replace替换内容中所有img
- JavaScript中的replace 达到replace.all函数替换的问题
- preg_match_all结合str_replace替换内容中所有img
- php preg_match_all结合str_replace替换内容中所有img
- Javascript正则表达式把所有空格替换为指定字符
- javascript三个字符处理函数:split join和replace replaceall
- javascript-replace()基础,一次完成将"<,>"替换"<>"实例
- Replace all Matches (替换所有匹配)
- javascript 替换字符串中的所有空格