# Regex for capturing images

**URL:** <https://www.ruby-forum.com/t/regex-for-capturing-images/154414>\
**Category:** Ruby\
**Created:** [November 29, 2008, 12:19am UTC](https://www.ruby-forum.com/t/regex-for-capturing-images/154414 "2008-11-29T00:19:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ponto](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/958977/32.png) [@ponto](https://www.ruby-forum.com/u/ponto)\
**Post date:** [November 29, 2008, 12:19am UTC](https://www.ruby-forum.com/t/regex-for-capturing-images/154414/1 "2008-11-29T00:19:32Z")

</div>

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:

[![](http://sub-domain.domain.net/path/folder/thum/figurename1010-thumb.jpg)](http://sub-domain.domain.net/path/folder/figurename1010.jpg) some text

rubular outputs me this:  
Match captures:  
Result 1

1. [http://sub-domain.domain.net/path/folder/figurename1010.jpg](http://sub-domain.domain.net/path/folder/figurename1010.jpg)  
Result 2
2. 

[http://sub-domain.domain.net/path/folder/thum/figurename1010-thumb.jpg](http://sub-domain.domain.net/path/folder/thum/figurename1010-thumb.jpg)

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?

---

<div class="post-metadata">

**Author:** ![ponto](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/958977/32.png) [@ponto](https://www.ruby-forum.com/u/ponto)\
**Post date:** [November 29, 2008, 2:15am UTC](https://www.ruby-forum.com/t/regex-for-capturing-images/154414/2 "2008-11-29T02:15:03Z")

</div>

> 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/figurename1010.jpg](http://sub-domain.domain.net/path/folder/figurename1010.jpg)”],  
[“[http://sub-domain.domain.net/path/folder/thum/figurename1010-thumb.jpg](http://sub-domain.domain.net/path/folder/thum/figurename1010-thumb.jpg)”]]

---

<div class="post-metadata">

**Author:** ![ponto](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/958977/32.png) [@ponto](https://www.ruby-forum.com/u/ponto)\
**Post date:** [April 20, 2009, 11:48am UTC](https://www.ruby-forum.com/t/regex-for-capturing-images/154414/3 "2009-04-20T11:48:45Z")

</div>

Hi All,

Get all images from given URL

Desktop Application from jazzez

Kindly go through below link and download the EXE file.

> **[jazzez-image-v2.exe | Powered by Box](https://app.box.com/s/m5vxqpr3r1)**
>
> Get all images from the given URL

Install in Windows machine and enjoy with impressed images
