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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM