'a2322bbc'.indexOf('b')  与
'a2322bbc'.search('b')都是忽略全局,返回第一次匹配到的元素下标index
                'a2322bbc'.search('b')都是忽略全局,返回第一次匹配到的元素下标index
                    
                    2018-01-31
                
            
                                已采纳回答 / 向世界问好
                                
                                                            <...图片...>第一次查找完会把lastIndex的值设为匹配到的字符串的最后一个字符的索引位置加1,第二次查找的时候会从lastIndex这个位置开始。所以,第二次查找从字符“b”开始,因此查不到“2bb3”。
                            
                        
                        2018-01-26
                
            老师例子中忘了加入index,实际应该这样:function(match, group{n个}, index, origin);
例如:
//输出index
'a1b2c3d4e5'.replace(/(\w)(\d)/g, function(match, g1, g2, index, origin){
console.log(index);
return g2; //此处是match,删掉匹配的字母
});
输出:0
2
4
6
8
"12345"
                例如:
//输出index
'a1b2c3d4e5'.replace(/(\w)(\d)/g, function(match, g1, g2, index, origin){
console.log(index);
return g2; //此处是match,删掉匹配的字母
});
输出:0
2
4
6
8
"12345"
                    
                    2018-01-18
                
            @mangoohohoho match是匹配为数组,如果过滤字母:'a1b2c3d4e5'.replace(/(\w)(\d)/g, function(match, g1, g2,  index, origin){
console.log(match);
return g2; //此处是match,删掉所有字母
});
输出:"a1"
"b2"
"c3"
"d4"
"e5"
"12345"
                console.log(match);
return g2; //此处是match,删掉所有字母
});
输出:"a1"
"b2"
"c3"
"d4"
"e5"
"12345"
                    
                    2018-01-18
                
             
             
        










