本文共 438 字,大约阅读时间需要 1 分钟。
正则表达式,
//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(不区分大小写)
转载地址:http://qzzwk.baihongyu.com/