Created
April 12, 2014 16:30
-
-
Save kalepail/10544488 to your computer and use it in GitHub Desktop.
Return first image url from a string of content
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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