码迷,mamicode.com
首页 > Web开发 > 详细

js正则中的贪婪和非贪婪模式问题总结

时间:2016-09-19 01:23:29      阅读:170      评论:0      收藏:0      [点我收藏+]

标签:

var b="abeeee:eeeee:eeeeeab";
        console.log(b.match(/e+\:e+/g));//["eeee:eeeee"]贪婪模式,只显示第一个匹配到的
        console.log(b.match(/e+?\:e+?/g));//["eeee:e", "eeee:e"]非贪婪模式,从前向后查询
        console.log(b.match(/e+\:(?=e+)/g));//["eeee:", "eeeee:"]
        console.log(b.match(/e+?\:(?=e+)/g));//["eeee:", "eeeee:"]
        console.log(b.match(/(?<=e+)?\:(?=e+)/g));//[":", ":"]
        console.log(b.match(/e+?\:(?!e+)/g));//null
        console.log(b.match(/(?:e+)?\:(?:e+?)/g));//["eeee:e", "eeee:e"]

 

js正则中的贪婪和非贪婪模式问题总结

标签:

原文地址:http://www.cnblogs.com/dupd/p/5883556.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!