日期:2014-05-16  浏览次数:20295 次

一个反向引用的问题
<script   language= "javascript ">
function   abc()
{
var   sToChange   =   "1234   5678 ";
var   reMatch   =   /(d{4})   (d{4})/;
var   sNew   =   sToChange.replace(reMatch, "$2   $1 ");
alert(sNew);
}
</script>
<body   onload= "abc() ">
</body>


alert输出的结果应该是5678   1234才对,但这个输出的结果是1234   5678怎么回事?

------解决方案--------------------
script language= "javascript ">
function abc()
{
var sToChange = "1234 5678 ";
var reMatch = /(\d{4}) (\d{4})/;
var sNew = sToChange.replace(reMatch, "$2 $1 ");
alert(sNew);
}
</script>
<body onload= "abc() ">