function testReplace(){
var arg = arguments;
var len = arg.length;
while(len--){
return '{' + arg[0] + '}';
}
}
var re = /\d+/g;
var str = "一回来北京快2年了,1眨眼就过去了";
var newStr = str.replace(re, testReplace);
alert(str); // 一回来北京快2年了,1眨眼就过去了
alert(newStr); // 一回来北京快{2}年了,{1}眨眼就过去了