星空网 > 软件开发 > Java

[RegExp]正则表达式中global模式的特性

一直不是很清楚javascript的global到底表现在哪些方面,所以今天特地做了几个测试:

var str = 'bbaaabb',  reg = /^b|b$/;  while(reg.test(str)){    str = str.replace(reg,'');    console.log(reg.lastIndex + ":" + str);  }

最终结果:

//0:baaabb//0:aaabb//0:aaab//0:aaa

但是如果稍做一些修改

var str = 'bbaaabb',  reg = /^b|b$/g;  while(reg.test(str)){    str = str.replace(reg,'');    console.log(reg.lastIndex + ":" + str);  }

最终结果则是:

//0:baaab//0:aaa


这样的结果说明,global模式下,在匹配到了开始的b字符后,还将继续匹配结尾的b字符,从而忽视掉中间"|"操作符。

 




原标题:[RegExp]正则表达式中global模式的特性

关键词:正则表达式

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

海运澳大利亚费用:https://www.goluckyvip.com/tag/33555.html
海运澳大利亚专线:https://www.goluckyvip.com/tag/33556.html
海运澳洲fba价格:https://www.goluckyvip.com/tag/33557.html
海运澳洲费用:https://www.goluckyvip.com/tag/33558.html
海运巴西专线:https://www.goluckyvip.com/tag/33559.html
阿里巴巴:https://www.goluckyvip.com/tag/3356.html
17万件月销量!Wildplus Beauty香薰身体精华油大热趋势 :https://www.kjdsnews.com/a/1836305.html
17万件月销量!Wildplus Beauty香薰身体精华油大热趋势 :https://www.goluckyvip.com/news/186214.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流