Q:

Regex to capture and store url

I'm very new to perl and I'm trying to harvest the links and images from a website. I'm currently reading about regular expressions and I've so far managed to get the lines of html that contain links or images (at least I believe so) with
/<img src|<a href/i     #I'm just comparing every line of html to this

But how do I capture and store the actual url? Basically to turn something like this: 
<img src="http://i1.nyt.com/images/2014/03/23/us/23marriage2/23marriage2-largeHorizontal375.jpg"

Into this: 
http://i1.nyt.com/images/2014/03/23/us/23marriage2/23marriage2-largeHorizontal375.jpg

A:

In general, I recommend using something like e.g. HTML::TreeBuilder rather than regular expressions to parse HTML.
Saying that, you can of course try and use regexes to fetch what you're after - but it is very dependent on your source material. Something that generically would capture an img src or a href would be something a bit like (this assumes things such as double quotes always being used, for example, and will be much more brittle than a parsing solution):
/<img[^>]*?src="([^"]*)"|<a[^>]*?href="([^"]*)"/i

Then if it matches, an image URL would be in $1, or a link would be in $2.

