js 知识

 <script>
        // 1.正则表达式.test(检索的字符串)   满足true  不满足false
        // []  匹配[]中的任意字符
        var reg = /^1[3-9]\d{9}$/;
        var phone = "11456789011";
        console.log(reg.test(phone));//false

        // 2.正则表达式.exec(检索的字符串)
        /* 
            检测通过则是返回数组 数组中包含检索通过的字符和下标以及其他信息  如果检索不到则是返回null
            不加g:每次都是从下标为0的位置开始检索 检测到一个就停止
            加g:从上次检索的位置开始进行查找  检索到一个就停止

            注意:检索到最后为null 为null再检索是从头开始
        */
        var str = "q1w2e3r4t5y6u7";
        var reg = /\d/g;
        console.log(reg.exec(str));//['1', index: 1, input: 'q1w2e3r4t5y6u7', groups: undefined]
        console.log(reg.exec(str));//['2', index: 3, input: 'q1w2e3r4t5y6u7', groups: undefined]
        console.log(reg.exec(str));//['3', index: 5, input: 'q1w2e3r4t5y6u7', groups: undefined]
        console.log(reg.exec(str));//4
        console.log(reg.exec(str));//5
        console.log(reg.exec(str));//6
        console.log(reg.exec(str));//7
        console.log(reg.exec(str));//null
        console.log(reg.exec(str));//1
        console.log(reg.exec(str));//2
    </script>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值