<SCRIPT LANGUAGE="JavaScript1.2">
re=/(\w+)\s(\w+)\s(\w+)/;
str="Johm Smith 123wsd";
newstr=str.replace(re,"$3,$2,$1");
document.write(newstr);
</SCRIPT>
re=/(\w+)\s(\w+)\s(\w+)/;
str="Johm Smith 123wsd";
newstr=str.replace(re,"$3,$2,$1");
document.write(newstr);
</SCRIPT>
re=/(\w+)\s(\w+)\s(\d+)/;
str="Johm Smith 123wsd";
newstr=str.replace(re,"$3,$2,$1");
document.write(newstr);
</SCRIPT>我用/d,是匹配一个数字,那后面的为什么还会显示出来?结果是这样的123,Smith,Johmwsd
re=/(\w+)\s(\w+)\s(\d+)/;
str="Johm Smith 123wsd";
newstr=str.replace(re,"$3,$2,$1");
document.write(newstr);
</SCRIPT>
我用上了d不是应该匹配数字的吗,但为什么后面的几个字母也显示出来?结果如下
123,Smith,Johmwsd