tags:

views:

31

answers:

2

If I had an html string containing this somewhere in the middle of it:

<img src="http://images.domain.com/Images/hello.jpg" alt="Failed to Load" />

What regex would I use in order to just obtain the name of the image file? i.e. hello.jpg

Currently I am using this:

(?<front>.*<img.*src="http://images.domain.com/Images/)(?&lt;imgName&gt;.*)"(?&lt;end&gt;.*)

However the value that it finds for the imgName group is:

hello.jpg" alt="Failed to Load

Does anyone know how to fix that?

+4  A: 

The easiest fix is to have the imgName group match anything except for quotes by changing .* to [^"]*:

(?<front>.*<img.*src="http://images.domain.com/Images/)(?&lt;imgName&gt;[^"]*)"(?&lt;end&gt;.*)
Quartermeister
+2  A: 

Please see why you shouldn't be trying this.

Anyway, try (?<imgName>.*?) instead.

strager
I know, I read that. A pure work of art.
Immanu'el Smith