js 正则所有a标签

1 var str = '<a href="/cms_files/filemanager/431831678/attach/20233/74d09820eed742dcb076df943a704747.xlsx">附件1:数据1.xlsx</a>dsfsaf345566..,.m,./..safesaf<a href="/cms_files/filemanager/431831678/attach/20233/320c2b11b91a47a8b53d4e848c356fe8.xlsx">附件2:(APP)数据.xlsx</a>addsafdsa,/,//.,,.,.dfsdf';
2 var reg =/<a[^>]*href=[ '"]([^"]*)[' "][^>]*>(.*?)<\/a>/g;
3 
4 var arr=[];
5 while(reg.exec(str)!=null)
6 {
7 arr.push(RegExp.$2 + "||" + RegExp.$1); //如果是RegExp.$1那么匹配的就是href里的属性了!
8 }

 

posted @ 2023-06-14 14:09  笠航  阅读(179)  评论(0编辑  收藏  举报