Skip to content

Instantly share code, notes, and snippets.

@kalepail
Created April 12, 2014 16:30
Show Gist options
  • Save kalepail/10544488 to your computer and use it in GitHub Desktop.
Save kalepail/10544488 to your computer and use it in GitHub Desktop.
Return first image url from a string of content
var rex = /<img[^>]+src="?([^"\s]+)"?[^>]*\/>/g;
for (var i = 0; i < count; i++) {
var content = obj[i].content,
img = content.match(rex);
var results = rex.exec(content);
if (results != null) {
var source = results[1];
obj[i].img = source;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment