Use regexp!
Something like this should do the trick:
html.match(/<img [^>]*src="([^"]*)"/g)
See working example here: http://www.rubular.com/r/f89Y9fHGtN (Caution: Ruby regexes are a bit different than JS ones, but I don't know such a cool tool for the latter.)
Regexp explained:
<img
– this matches beginning of the tag.
[^>]*
– a bit tricky. This gets rid of things in front of src
argument (alt
argument, for example). This version fails when there's a >
char inside of an argument, which probably should not happen. You may try replacing this part with .*
, which will work in that case, failing on the other hand when an argument value ends with src=
.
src="
– this finds the src argument.
([^"]*)
– captures the URL inside.
"
– finds end of the value.
Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems.