js 实现每隔几个字符进行添加字符串

function Xreplace(str,length,reversed)
{
var re = new RegExp("\\d{1,"+length+"}","g");
ma = str.match(re);
if(reversed)ma.reverse();
return ma.join("a") + "a";//最后面不要"a" 就去掉( + "a")
}

 

alert(Xreplace("000100020003",4));
alert(Xreplace("000100020003",4,true));
alert(Xreplace("000100020003",4,false));

 

posted @ 2017-11-09 17:56  珈子  阅读(9330)  评论(0编辑  收藏  举报