Forum: Ruby regex for capturing images

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
E6470df4ee8aa5563dc27a777ef9a46b?d=identicon&s=25 Ponto André (ponto)
on 2008-11-29 00:19
ok, i've written this regex:
/(https?:(?:/*\w*\.*-*)*(?:\.gif|\.jpg|\.bmp|\.png|\.jpeg))/i

i've tested it on rubular.

and for this example text:
<p><a href='http://sub-domain.domain.net/path/folder/figurenam...
target=_blank><img style='float:left;margin:8px' border=0
src='http://sub-domain.domain.net/path/folder/thum/figu...
some text</p>

rubular outputs me this:
Match captures:
Result 1
   1. http://sub-domain.domain.net/path/folder/figurename1010.jpg
Result 2
   1.
http://sub-domain.domain.net/path/folder/thum/figu...

but in my code:
matchdata =
text.match(/(https?:(?:\/*[a-zA-Z]*\.*-*\d*)*(?:\.gif|\.jpg|\.bmp|\.png|\.jpeg))/i).captures
puts matchdata.size

size prints me "1".

am i capturing wrong?
3d401468ea7d69980d5cf9ecd18ce65a?d=identicon&s=25 Constantine Karnacevych (digital)
on 2008-11-29 02:15
> but in my code:
> matchdata =
> 
text.match(/(https?:(?:\/*[a-zA-Z]*\.*-*\d*)*(?:\.gif|\.jpg|\.bmp|\.png|\.jpeg))/i).captures
> puts matchdata.size
>
> size prints me "1".
>
> am i capturing wrong?

use text.scan() which matches all occurences

p
text.scan(/(https?:(?:\/*\w*\.*-*)*(?:\.gif|\.jpg|\.bmp|\.png|\.jpeg))/im)

=> [["http://sub-domain.domain.net/path/folder/figurenam...],
["http://sub-domain.domain.net/path/folder/thum/figu...]]
Da22709962fc0cf31068e779c78ab6be?d=identicon&s=25 Raveendran .P (jazzezravi)
on 2009-04-20 11:48
Hi All,

Get all images from given URL

Desktop Application from jazzez

Kindly go through below link and download the EXE file.

http://www.box.net/shared/m5vxqpr3r1

Install in Windows machine and enjoy with impressed images
This topic is locked and can not be replied to.