我现在遇到的问题是:我现在只把包含1的替换掉,而且1有可能在开头,也有可能在结尾,也有可能在中间,该怎么过滤呀。

解决方案 »

  1.   

    是指? s = s.replace(/1/g,""); 
      

  2.   


    <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
            <title></title>
            <script language="JavaScript" type="text/javascript">
                window.onload=function(){
                    var s="2345167819";
                    var rex=/([0|2-8]*?)[1]*([0|2-8]*?)/g
                    alert(s.replace(rex,"$1$2"));
                }        </script>
        </head>
        <body>
        </body>
    </html>
      

  3.   


    var str="1abcd12345我的故事12345671";
    str=str.replace(/1/g,"");是这样?
      

  4.   


    var str="1abcd12345我的故事12345671";
    str=str.replace(/1{1}/g,"");是不是这样?
      

  5.   

    [code]
    <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
            <title></title>
            <script language="JavaScript" type="text/javascript">
                window.onload=function(){
                    var s="23451167819";
                    var rex=/([0|2-8]*?)(11)*[1]*([0|2-8]*?)/g
                    alert(s = s.replace(rex,"$1$2$3"));
                }        </script>
        </head>
        <body>
        </body>
    </html>
    [/code]
      

  6.   

    猜的...这样吧?<html xmlns="http://www.w3.org/1999/xhtml">
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
            <title></title>
            <script language="JavaScript" type="text/javascript">
                window.onload=function(){
                    var s="23451167819";
                    var rex=/([0|2-8]*?)(11)*[1]*([0|2-8]*?)/g
                    alert(s = s.replace(rex,"$1$2$3"));
                }        </script>
        </head>
        <body>
        </body>
    </html>
      

  7.   

    笨点做法
    var str="1abcd12345我的故事112345671";
    str=str.replace(/11/g,"|X|");
    str=str.replace(/1/g,"");
    str=str.replace(/|X|/g,"11"); 再换回来,
      

  8.   


                 var s="23145116711819";
                 var rex=/(11*?)1/g
                 alert(s = s.replace(rex,""));
      

  9.   

    貌似读错题了..                var s="231451167111819";
    s = s.replace(/11|(1)/g, function(l, $1){ return ($1 ? "" : l)});
    alert(s)   
      

  10.   


    //更简单的...
    <script type="text/javascript">
    <!--
    var s="231451167111819";
    s = s.replace(/(11)|1/g, '$1');
    alert(s) 
    //-->
    </script>