<html>
<head>
<script language='javascript'>
var strSrc="xxa1b01c001yya2b02c002zz";
var re=/a(\d)b(\d{2})c(\d{3})/gi;
var arr,count=0;
while((arr=re.exec(strSrc))!=null)
{displayResult();alert('d');
}
function displayResult(){
document.write("<p>这是用正则表达式/"+re.source+"/gi对字符串<br>\""+RegExp.input+"\"进行第"+(++count)+"次搜索的结果:<br>");
document.write("RegExp.index为"+)
}
document.write('RegExp.index为'+RegExp.index+"<br>");
</script>
</head>
<body></body>
</html>

解决方案 »

  1.   


    <html>
    <head>
    <script language='javascript'>
    var strSrc="xxa1b01c001yya2b02c002zz";
    var re=/a(\d)b(\d{2})c(\d{3})/gi;
    var arr,count=0;
    while((arr=re.exec(strSrc))!=null)
    {displayResult();alert('d');
    }
    function displayResult(){
    document.write(" <p>这是用正则表达式/"+re.source+"/gi对字符串 <br>\""+RegExp.input+"\"进行第"+(++count)+"次搜索的结果: <br>");
    document.write("RegExp.index为"+)
    }
    document.write('RegExp.index为'+RegExp.index+" <br>");
    </script>
    </head>
    <body> </body>
    </html>
      

  2.   

    代码有错
    document.write("RegExp.index为"+) 
      

  3.   


    <html>
    <head>
    <script type='text/javascript'>
    var strSrc="xxa1b01c001yya2b02c002zz";
    var re=/a(\d)b(\d{2})c(\d{3})/gi;
    var arr,count=0;
    while((arr=re.exec(strSrc))!=null){
        displayResult();//alert('d');
    }
    function displayResult(){
        document.write(" <p>这是用正则表达式/"+re.source+"/gi对字符串 <br>\""+RegExp.input+"\"进行第"+(++count)+"次搜索的结果: <br>");
        document.write('RegExp.index为'+arr.index+" <br>匹配内容为:"+arr[0]+"<br/>");
    }
    </script>
    </head>
    <body> </body>
    </html>