JavaScript正则获取a标签中的path路径值-流程引擎-计算引擎

直接上代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
//获取附件中的链接地址
            function get_file_path_from_encode_value(x) {
                var arrLink = [];
                x.replace(/<a [^>]*path=['"]([^'"]+)[^>]*/gi, function (match, capture) {
                    arrLink.push(capture)
                });
                if (arrLink.length > 0) {
                    return arrLink;
                }
            }
 
             
            //举个例子
            var ssss = decodeURIComponent("%3Ctbody%3E%3Ctr%3E%20%20%20%20%3Ctd%3E%20%20%20%20%20%20%20%20%3Ca%20style%3D%22cursor%3Apointer%3Bdisplay%3Ablock%3B%22%20onclick%3D%22openf(this)%22%20path%3D%22%2Fupload%2Ffiles%2F5d1f9b6ec370468b95ede27ea70fa092_%E4%B8%AD%E8%AF%95%E5%9F%BA%E5%9C%B0.xlsx%22%3E%E4%B8%AD%E8%AF%95%E5%9F%BA%E5%9C%B0.xlsx%3C%2Fa%3E%20%20%20%20%3C%2Ftd%3E%20%20%20%20%3Ctd%3E%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2010%20KB%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3C%2Ftd%3E%20%20%20%20%3Ctd%3E%20%20%20%20%20%20%20%20%3Ca%20name%3D%22adelete%22%20onclick%3D%22deletefiles(this)%22%20style%3D%22cursor%3A%20pointer%3B%20color%3A%20red%3B%22%3E%E5%88%A0%E9%99%A4%3C%2Fa%3E%20%20%20%20%3C%2Ftd%3E%3C%2Ftr%3E%3Ctr%3E%20%20%20%20%3Ctd%3E%20%20%20%20%20%20%20%20%3Ca%20style%3D%22cursor%3Apointer%3Bdisplay%3Ablock%3B%22%20onclick%3D%22openf(this)%22%20path%3D%22%2Fupload%2Ffiles%2Fc2d40849476e42b0a38de0c1aa0f0aa6_%E4%BB%AA%E5%99%A8%E7%AE%A1%E7%90%86.xlsx%22%3E%E4%BB%AA%E5%99%A8%E7%AE%A1%E7%90%86.xlsx%3C%2Fa%3E%20%20%20%20%3C%2Ftd%3E%20%20%20%20%3Ctd%3E%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2010%20KB%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3C%2Ftd%3E%20%20%20%20%3Ctd%3E%20%20%20%20%20%20%20%20%3Ca%20name%3D%22adelete%22%20onclick%3D%22deletefiles(this)%22%20style%3D%22cursor%3A%20pointer%3B%20color%3A%20red%3B%22%3E%E5%88%A0%E9%99%A4%3C%2Fa%3E%20%20%20%20%3C%2Ftd%3E%3C%2Ftr%3E%3C%2Ftbody%3E");
 
            var arr = get_file_path_from_encode_value(ssss);
 
            for (var i = 0; i < arr.length; i++) {
                alert(arr[i]);
            }

  

 

当然可以放到方法里面做decode操作:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//获取附件中的链接地址
           function get_file_path_from_encode_value(x) {
               x = decodeURIComponent(x);
               var arrLink = [];
               x.replace(/<a [^>]*path=['"]([^'"]+)[^>]*/gi, function (match, capture) {
                   arrLink.push(capture)
               });
               if (arrLink.length > 0) {
                   return arrLink;
               }
           }
 
           var arr = get_file_path_from_encode_value("%3Ctbody%3E%3Ctr%3E%20%20%20%20%3Ctd%3E%20%20%20%20%20%20%20%20%3Ca%20style%3D%22cursor%3Apointer%3Bdisplay%3Ablock%3B%22%20onclick%3D%22openf(this)%22%20path%3D%22%2Fupload%2Ffiles%2F5d1f9b6ec370468b95ede27ea70fa092_%E4%B8%AD%E8%AF%95%E5%9F%BA%E5%9C%B0.xlsx%22%3E%E4%B8%AD%E8%AF%95%E5%9F%BA%E5%9C%B0.xlsx%3C%2Fa%3E%20%20%20%20%3C%2Ftd%3E%20%20%20%20%3Ctd%3E%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2010%20KB%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3C%2Ftd%3E%20%20%20%20%3Ctd%3E%20%20%20%20%20%20%20%20%3Ca%20name%3D%22adelete%22%20onclick%3D%22deletefiles(this)%22%20style%3D%22cursor%3A%20pointer%3B%20color%3A%20red%3B%22%3E%E5%88%A0%E9%99%A4%3C%2Fa%3E%20%20%20%20%3C%2Ftd%3E%3C%2Ftr%3E%3Ctr%3E%20%20%20%20%3Ctd%3E%20%20%20%20%20%20%20%20%3Ca%20style%3D%22cursor%3Apointer%3Bdisplay%3Ablock%3B%22%20onclick%3D%22openf(this)%22%20path%3D%22%2Fupload%2Ffiles%2Fc2d40849476e42b0a38de0c1aa0f0aa6_%E4%BB%AA%E5%99%A8%E7%AE%A1%E7%90%86.xlsx%22%3E%E4%BB%AA%E5%99%A8%E7%AE%A1%E7%90%86.xlsx%3C%2Fa%3E%20%20%20%20%3C%2Ftd%3E%20%20%20%20%3Ctd%3E%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2010%20KB%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3C%2Ftd%3E%20%20%20%20%3Ctd%3E%20%20%20%20%20%20%20%20%3Ca%20name%3D%22adelete%22%20onclick%3D%22deletefiles(this)%22%20style%3D%22cursor%3A%20pointer%3B%20color%3A%20red%3B%22%3E%E5%88%A0%E9%99%A4%3C%2Fa%3E%20%20%20%20%3C%2Ftd%3E%3C%2Ftr%3E%3C%2Ftbody%3E");
 
           for (var i = 0; i < arr.length; i++) {
               alert(arr[i]);
           }

  

 

done

 

posted @   liskov_design  阅读(151)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· DeepSeek 开源周回顾「GitHub 热点速览」
点击右上角即可分享
微信分享提示