I have an app that is being fed HTML into a variable. I need to find the url for the first image file in the HTML (if there is a link at all). This is what I have right now:
var media = row.content.substring(row.content.indexOf('<img src="') + 1, row.content.indexOf('"'));
However, this is not grabbing the correct information. Can anyone see what I’m doing wrong?
Thanks!
Your 2nd
indexOfis going to return, at the very least, the"from<img src=", possibly an earlier one. Try:which will ensure that it finds the first quote after the one in the img src.
A better way to do this is with a regex: