正则表达式match方法和search方法

正则表达式,

          //match() 方法可在字符串内检索指定的值 找到返回相关数据,找不到返回null
          var part = /Box/ig;
          var str = "this is box,is a Box";
          console.log(str.match(part)); //在str中去匹配查找是否有Box,有返回相关的信息
          // 返回来的是数组 ["box","Box"] {ma qi}


            //使用search来查找匹配的数据,(找到返回匹配对应的下标值) 找不到返回-1。
            var part = /Box/ig;
            var str = "this is box,is a Box";
            console.log(str.search(part));//返回8 说明从下标为8开始就匹配到这个字符了Box(不区分大小写)
原文地址:https://www.cnblogs.com/IwishIcould/p/12642761.html