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

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"]

 

posted @ 2016-09-18 23:47  杜培东  阅读(6205)  评论(0编辑  收藏  举报