编辑代码

//十一、exec的使用场景以及lastindex
//如果只使用match方法,那么正则如果带g模式匹配,那么查询的结果全,但是展示的信息不全
//如果不带g,那么结果不全,只显示第一个查询到的结果,但是的信息全
//如果需要展示的信息全,查询的也全,那么就需要正则方法exec
//每次exec,正则的查询索引就会往后延续,怎么看索引,就是正则的lastindex
    let hd11="houdunren"
    let reg11=/\w/g
    console.log(reg11.lastIndex)
    console.log(reg11.exec(hd11))
    console.log(reg11.lastIndex)
    console.log(reg11.exec(hd11))
    //常常这样使用,达到match+g且展示ok 
    while(res=reg11.exec(hd11)){
        console.log(res)
    }