js高程里的例子(書中P107),不明白為何下面的第二次執行,alert(matches.index)的值是5?為何alert(matches[0])是bat?應該是我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對exec本身的影響是,當一個具有g的正則表達式調用exec()時,他將該對象的lastIndex設置到緊接這匹配子串的字符位置.當第二次調用exec時將從lastIndex所指示的字符位置開始檢索"看到這句話仍然沒能理解,為何輸出是5?
js中,exec()方法,為何這里的index是5?
慕田峪9158850
2019-04-10 20:48:52