<script>var str ="scat and dog,cat and dog";var reg =/cat/g;//全局匹配
reg.lastIndex=20;// lastIndex对match()无效//如果没有全局匹配则返回["cat"]
console.log(str.match((reg));//["cat","cat"]
console.log(reg.exec(str));["cat",index:1,input:"scat and dog,cat and dog"]
console.log(reg.exec(str));["cat",index:13,input:"scat and dog,cat and dog"]//返回第一个匹配的位置
console.log(str.search(reg))//1</script>