js 正则

作者: coolkid_carryon | 来源:发表于2018-09-20 18:44 被阅读0次

    练习:

    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="utf-8" />
            <title>replace</title>
            <script type="text/javascript">
                var str0 = 'Once1a2wolf, 3always4a5wolf!';
                console.log(str0.replace(/\d/g,' '));
    
                var str1 = 'sdqqfgkkkhjppppkl';
                console.log(str1.replace(/(.)\1+/g,'$').split('$'));
    
                var str2 = '我我....我...我.要...要要...要学....学学..学.编..编编.编.程.程.程..程';
                console.log(str2.replace(/\.+/g,'').replace(/(.)\1+/g,'$1'));
    
                var str3 = '我的手机号码是17688888888,曾经用过13187654321,还用过13512345678';
                console.log(str3.match(/1[3578]\d{9}/g));
            </script>
        </head>
        <body>
            
        </body>
    </html>
    

    效果图:


    regexp

    相关文章

      网友评论

          本文标题:js 正则

          本文链接:https://www.haomeiwen.com/subject/iownnftx.html