其他分享
首页 > 其他分享> > es6 正则扩展-正反断言

es6 正则扩展-正反断言

作者:互联网

正则扩展-正反断言

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>es9-正则扩展-正反断言</title>

</head>
<body>


<script>
    //字符串
    let str = 'telephone:15278378872;name:x小明';
    //正则-正向断言
    let reg = /\d+(?=;)/;
    //执行
    let result = reg.exec(str);
    console.log(result);

    //正则-反向断言
    let reg2 = /(?<=:)\d+/;
    //执行
    let result2 = reg2.exec(str);
    console.log(result2);
</script>
</body>
</html>

标签:es6,断言,正反,正则,let,result,reg
来源: https://www.cnblogs.com/hu308830232/p/14912643.html