in reply to Regex simple quicky question :)

Assuming the image name doesn't have any spaces in it, you could do it like this:

if ( $url =~ m!/([^/]+\.(?:jpe?g|gif|png|tiff?)\b)!i ) { print "Found $1\n"; }

The way this works is as follows:

m! # Use an alternate delimiter. / # Match a '/' character to anchor off of. ( # Start a capturing parenth. [^/]+ # Match any number of non-'/' characters. \. # Match the '.' character. (?: # Group or constrain without capturing. jpe?g # jpg or jpeg. | gif # or gif | png # or png | tiff? # or tif or tiff ) # End the grouping/constraining parens. \b # Make sure that tiff isn't tiffany, for # example. ) # End the capture. !ix # Case insensitive /i (Ignore the x, it's only # necessary in this expanded example.

If the URL is encoded, so that spaces have become '+' characters, etc., you will need to decode the URL first, or else filenames containing spaces will be mangled. That particular issue isn't a regexp issue, just the way URL's get encoded.


Dave