var b="aeg12";
b.replace(/(\w{2})(\d+)/g,function(match,p1,p2,index,string){});
比如我现在要把匹配到的第一个分组和第二个分组分别替换成其他东西要怎么做啊
谢谢!
我给你一个例子吧,包你看完就明白了:
'border-top'.replace(/(\-)([a-z])/g, function(match, $1, $2, offset, string) {
console.log(match);
console.log($1);
console.log($2);
console.log(offset);
console.log(string);
$1 = '';
$2 = $2.toUpperCase();
return $1 + $2;
})
// => -t
// => -
// => t
// => 6
// => border-top
// => "borderTop"