for(var n in defaults){
if(new RegExp("("+ n +")").test(format)){
param = RegExp.$1;
value = ""+defaults[n];
if(value.length===1){value="0"+value;}
if(param.length===1 && value.length<=2){value="0"+ value;}
format = format.replace(param, value);
}
}红字部分
param = RegExp.$1;
我不明白$1 ,好象在正则表达式中有 $1...$9
谁能帮我详细描述下用法哦,最好给我一个例题,谢谢
if(new RegExp("("+ n +")").test(format)){
param = RegExp.$1;
value = ""+defaults[n];
if(value.length===1){value="0"+value;}
if(param.length===1 && value.length<=2){value="0"+ value;}
format = format.replace(param, value);
}
}红字部分
param = RegExp.$1;
我不明白$1 ,好象在正则表达式中有 $1...$9
谁能帮我详细描述下用法哦,最好给我一个例题,谢谢
var re=/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/g //匹配IP地址的正则表达式
if(re.test(ip))
{
if( RegExp.$1 <256 && RegExp.$2<256 && RegExp.$3<256 && RegExp.$4<256)
return true;
}
RegExp.$1就代表ip中在re的第一个括号的内容
RegExp.$2就代表ip中在re的第二个括号的内容
以此类推~~~