zoukankan      html  css  js  c++  java
  • js中如何利用正则匹配多个全部数据

    正则表达式后面加g表示多次匹配

    方式一:match

    返回数组

    方式二

    exec

    实例如下:

    <script>
    
       
    
     var str='<a href="//www.aliexpress.com/store/product/OOOT-BAORJCT-174296-22mm-10yard-lot-cartoon-Ribbons-Thermal-transfer-Printed-grosgrain-Wedding-Accessories-DIY-handmade/2349150_32810795709.html" rel="external nofollow" rel="external nofollow" title="OOOT BAORJCT 174296 22mm 10yard/lot cartoon Ribbons Thermal transfer Printed grosgrain Wedding Accessories DIY handmade material">OOOT BAORJCT 174296 22mm 10yard/lot cartoon Ribbons...</a><a href="//www.aliexpress.com/store/product/OOOT-BAORJCT-174296-22mm-10yard-lot-cartoon-Ribbons-Thermal-transfer-Printed-grosgrain-Wedding-Accessories-DIY-handmade/2349150_32810795709.html" rel="external nofollow" rel="external nofollow" title="999OOOT BAORJCT 174296 22mm 10yard/lot cartoon Ribbons Thermal transfer Printed grosgrain Wedding Accessories DIY handmade material">OOOT BAORJCT 174296 22mm 10yard/lot cartoon Ribbons...</a>';
    
    var reg=/title="(.*?)">/g;
    
    var res = str.match(reg);
    
    console.log(str.match(reg));
    
       
    
    while( res = reg.exec(str))
    
    {
    
     console.log(res[1]);
    
    }
    
    </script>
    

      

  • 相关阅读:
    curl 命令行使用参考
    PHP 输出json_encode 空白的检查
    RAM和ROM
    浮点数
    负数补码
    位运算
    无法加载文件 C:UsershuangshiminAppDataRoaming pmwechat-terminal.ps1,因为在此系统上禁止运行脚本
    windows + php + shell_exec 执行失败的可能原因
    Ubuntu 发送邮件
    红黑树
  • 原文地址:https://www.cnblogs.com/mo3408/p/12649732.html
Copyright © 2011-2022 走看看