js高程里的例子(書中P107),不明白為何下面的第二次執(zhí)行,alert(matches.index)的值是5?為何alert(matches[0])是bat?應(yīng)該是我exex()方法沒理解透。vartext="cat,bat,sat,fat";varpattern1=/.at/g;varmatches=pattern1.exec(text);alert(matches.index);//0alert(matches[0]);//catalert(pattern1.lastIndex);//3----------matches=pattern1.exec(text);alert(matches.index);//5alert(matches[0]);//batalert(pattern1.lastIndex);//8搜索之后,"有g(shù)對(duì)exec本身的影響是,當(dāng)一個(gè)具有g(shù)的正則表達(dá)式調(diào)用exec()時(shí),他將該對(duì)象的lastIndex設(shè)置到緊接這匹配子串的字符位置.當(dāng)?shù)诙握{(diào)用exec時(shí)將從lastIndex所指示的字符位置開始檢索"看到這句話仍然沒能理解,為何輸出是5?
js中,exec()方法,為何這里的index是5?
牧羊人nacy
2019-04-19 16:13:14