regex extract img src javascript

前端 未结 3 759
轮回少年
轮回少年 2021-01-06 17:41

I am trying to extract the img and src from a long html string.

I know there are a lot of questions about how to do this, but I have tried and gotten the wrong resu

3条回答
  •  醉梦人生
    2021-01-06 18:33

    Not a big fan of using regex to parse html content, so here goes the longer way

    var url = "";
    var tmp = document.createElement('div');
    tmp.innerHTML = url;
    var src = tmp.querySelector('img').getAttribute('src');
    snippet.log(src)
    
    

提交回复
热议问题