var s = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890';
function f(s, width){
var a=new RegExp('[\\s\\S]{1,'+(width || 4)+'}', 'g');
return s.replace(
a,
function(K,M,L,N){
console.log('==='+K);//第一个参数:匹配项
console.log('---'+M);//第一个参数:匹配项的起始index
console.log('---'+L);//整个字符串
console.log('---'+N);//undefined
return '^' + new Array(K.length).join(' ');
});
}
console.log(f(s, 4));
转载于:https://www.cnblogs.com/sking7/archive/2011/10/26/2224923.html