let str=`
<ul>
<li>
<a>肖申克的救赎</a>
<p>上映日期:1994-09-10</p>
</li>
<li>
<a>阿甘正传</a>
<p>上映日期:1994-07-06</p>
</li>
</ul>`;
const reg=/<li>.*?<a>(.*?)<\/a>.*?<p>(.*?)<\/p>/gs;
let result;
let data=[];
while (result=reg.exec(str)){
console.log(result);
data.push({title:result[1],time:result});
}
其中while(result=reg.exec(str))表示先将reg.exec(str)的第一次匹配值赋值给result,接着循环匹配赋值,直到整个字符串匹配完成,结束while循环
while (result=reg.exec(str)){
console.log(result);
data.push({title:result[1],time:result});
}