Extract image src from a string

前端 未结 5 517
遇见更好的自我
遇见更好的自我 2020-11-30 06:02

I\'m trying to match all the images elements as strings,

This is my regex:

html.match(/]+src=\"http([^\">]+)/g);

Th

5条回答
  •  自闭症患者
    2020-11-30 06:26

    Perhaps this is what you are looking for:

    What I did is slightly modified your regex then used the exec function to get array of matched strings. if you have more then 1 match the other matches will be on results[2], results[3]...

    var html = '';
    
    var re = /]+src="http:\/\/([^">]+)/g
    var results = re.exec(html);
    
    var source = results[1];
    alert(source);
    

提交回复
热议问题