##正则
<script>
//正则的实例方法
var reg=/cat/;//字面量
var reg=new RegExp('cat');//构造函数不常用
var str=" cat and dog";
console.log(reg.test(str))//匹配字符串中是否存在cat,返回布尔值
//true
</script>
<script>
var reg=/cat/;
var str="cat and dog cat"
console.log(reg.lastIndex)//0
console.log(reg.test(str))//true
console.log(reg.lastIndex)//15
//lastIndex属性指定开始搜索的位置
</script>
<script>
var reg=/cat/;
var str="cat and dog cat";
//正则实例对象的exec方法,用来返回匹配结果。如果发现匹配,就返回一个数组,成员是匹配成功的子字符串,否则返回null。
console.log(reg.lastIndex)//0
console.log(reg.exec(str));
console.log(reg.lastIndex)
console.log(reg.exec(str));
console.log(reg.lastIndex)
console.log(reg.exec(str));
while(true){
var match=reg.exec(str);
if(!match)break;
console.log(match.index+":"+match[0])
}
</script>