js的Math和正则

        /*
        * 创建正则方式,"g"表示全局通用,"i"表示大小写,"gi"表示通用和大小写
        */
        var re1 = new RegExp("\d+","g"); //匹配规则
        alert(re1.test("ab12ds")) ; //返回ture

         var re2 = /\d+/g;//匹配规则
        alert(re2.test("fsd5fsd23fsd2f")) //返回ture


        var s = "asb12d56fg";
        alert(s.match(re2)) ; //返回内容

        alert(s.search(re2)); //返回下标

        alert(s.split(re2));  //按数字分割

        alert(s.replace(re2,":")) ; //数字替换成:

        //Math对象,不需要创建直接使用

        alert(Math.max(1,3,5)); //最大值
        alert(Math.pow(2,3));  //2的几次方

猜你喜欢

转载自www.cnblogs.com/TKOPython/p/12820661.html
今日推荐