<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>lastIndex</title>
</head>
<body>
<script type="text/javascript">
/*
在全局匹配模式下, 可以指定要查找的字符串执行多次匹配,
每次匹配使用当前值作为在目标字符串中开始查找的起始位置.
lastIndex属性的初始位置 为 0. 找到匹配项后 lastIndex 的值被重置为匹配内容的下一个字符的索引位置, 用来标识下次执行匹配时的开始查找位置
*/
var reg1 = /\d/g; // \d 用来 匹配数字
var str1 = 'as4f65ase4';
console.log('从' + reg1.lastIndex + '开始查找');
console.log(reg1.exec(str1));
console.log('从' + reg1.lastIndex + '开始查找');
console.log(reg1.exec(str1));
console.log('从' + reg1.lastIndex + '开始查找');
console.log(reg1.exec(str1));
console.log('从' + reg1.lastIndex + '开始查找');
</script>
</body>
</html>
上述运行结果: