substring/regex to get a src value held in a string

前端 未结 7 1084
花落未央
花落未央 2021-01-02 05:25

I have a string with the value:

var string = \"\'\'
Some plain text
相关标签:
7条回答
  • 2021-01-02 06:22

    One way to do it is to use regular expressions.

    var str = "<img alt='' src='http://api.com/images/UID' /><br/>Some plain text<br/><a href='http://www.google.com'>http://www.google.com</a>";
    
    var regex = /<img.*?src='(.*?)'/;
    var src = regex.exec(str)[1];
    
    console.log(src);
    
    0 讨论(0)
提交回复
热议问题