# Regular Expressions

**URL:** <https://rubytalk.org/t/regular-expressions/48643>\
**Category:** ruby-talk\
**Created:** [27 August 2008 03:20 UTC](https://rubytalk.org/t/regular-expressions/48643 "2008-08-27T03:20:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Newb\_Newb](https://avatars.discourse-cdn.com/v4/letter/n/b9e5f3/32.png) [@Newb\_Newb](https://rubytalk.org/u/Newb_Newb)\
**Post date:** [27 August 2008 03:20 UTC](https://rubytalk.org/t/regular-expressions/48643/1 "2008-08-27T03:20:56Z")

</div>

Pls Any one Help...  
what is the regular expressions to Extract the image url which contains  
.png .gif .jpg file extensions.

&nbsp;&nbsp;&nbsp;To Extract the file Name from the image url what Regular Expressions  
has to Be Used.  
&nbsp;&nbsp;&nbsp;Nothing Found to Be working.I m Still On the Confusion.  
&nbsp;&nbsp;&nbsp;Pls Help

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![Phlip1](https://avatars.discourse-cdn.com/v4/letter/p/df788c/32.png) [@Phlip1](https://rubytalk.org/u/Phlip1)\
**Post date:** [27 August 2008 04:10 UTC](https://rubytalk.org/t/regular-expressions/48643/2 "2008-08-27T04:10:35Z")

</div>

Newb Newb wrote:

> Pls Any one Help...  
> what is the regular expressions to Extract the image url which contains  
> png .gif .jpg file extensions.
> 
> &nbsp;&nbsp;&nbsp;To Extract the file Name from the image url what Regular Expressions  
> has to Be Used.  
> &nbsp;&nbsp;&nbsp;Nothing Found to Be working.I m Still On the Confusion.  
> &nbsp;&nbsp;&nbsp;Pls Help

You have asked this question before; this might make some here concerned you won't use the answers already provided.

Your best bet has always been Hpricot, to \_find\_, \_store\_, and optionally \_erase\_ the image sources. You already posted a solution with .search('//img'). The step to \_store\_ the images would be something like this:

&nbsp;&nbsp;doc.search("//img").each do |img|  
&nbsp;&nbsp;&nbsp;&nbsp;puts img.attributes['src']  
&nbsp;&nbsp;end

A further regexp using /.jpg$/ would match strings with .jpg on the end, but be warned there are many variations of image filenames, including, for example, .JPEG.

Please post back what you did with this advice (if anything!), instead of continuing to ask the same question over and over again!

> **···**
>
> --  
> &nbsp;&nbsp;&nbsp;Phlip
