var str="2015-9-22 13:12:0";
str+=‘ ‘;
var ary=["年","月","日","时","分","秒"];
var reg=/(\d+)(-)(\d+)(-)(\d+)(\s)(\d+)(:)(\d+)(:)(\d+)(\s)/g;
var arr=[];
var res=str.replace(reg,function(){
var i=1;
var j=1;
var n=0;
while(i<=12){
arr.push(arguments[i]);
i++;
}
while(n<10){
n=j*2;
j++;
arr[n]=ToDouble(arr[n]);
}
for (var i = 0; i < ary.length; i++) {
var num=i*2+1;
arr[num]=ary[i];
}
function ToDouble(num){
return num>10?num:"0"+num;
}
var res=arr.join(‘‘);
return res;
});
console.log(res);
var str="zhu feng pei xun";//首字母大写
var reg=/\s([a-z])/g;
var res=str.replace(reg,function(){
return arguments[1].toUpperCase();
});
var reg=/[a-z]/;
var res=res.replace(reg,function(){
return arguments[0].toUpperCase();
});
console.log(res);
console.log(‘-----‘);
var str="2015-09-22 13:12:00",reg=/^(\d{4})[-](\d{1,2})[-](\d{1,2})[\s](\d{1,2})[:](\d{1,2})[:](\d{1,2})$/g,ary=[];
str.replace(reg,function(){
ary=[].slice.call(arguments).splice(1,6);
});
//var ary=["年","月","日","时","分","秒"];
var ResStr="{0}年{1}月{2}日 {3}时{4}分{5}秒";
//var ary=["2015","9","22","13","12","0"];
var reg=/{(\d)}/g;
var res=ResStr.replace(reg,function(){
//console.log(arguments);
var num=arguments[1],val=ary[num];
val.length===1?val="0"+val:void 0;
return val;
});
console.log(res);