JS Regex to find href of several a tags

后端 未结 9 1198
野性不改
野性不改 2020-12-28 08:04

I need a regex to find the contents of the hrefs from these a tags :

9条回答
  •  Happy的楠姐
    2020-12-28 08:47

    var str = "";
    
    str += "

    "; str += "delete"; str += "

    ";

    var matches = [];
    
    str.replace(/href=("|')(.*?)("|')/g, function(a, b, match) {
      matches.push(match);
    });
    
    console.log(matches);
    

    or if you don't care about the href:

    var matches = str.match(/href=("|')(.*?)("|')/);
    
    console.log(matches);
    

提交回复
热议问题