Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

regex image source html file 1

Status
Not open for further replies.

safra

Technical User
Jan 24, 2001
319
NL
Hi,

Anyone can help me with the regular expression to find all file locations of images in an html file?

Thanks!
 
this kind of thing:-

$/ = undef;
open (INFILE, &quot;< html.txt&quot;);
$_ = <INFILE>;
close INFILE;

while (m/<img src=([^ ]+)/ig) {
print &quot;$1\n&quot;;
}



Kind Regards
Duncan
 
You should only use a solution like that if you know that there won't be a line break in the tag and you know the src attribute is always going to be the first one. I.e., neither of the following will work:
Code:
<img
src=&quot;blah.png&quot; />
Code:
<img alt=&quot;A picture&quot; src=&quot;blah.png&quot; />

If you're going to be parsing pages written by others, try using a module like HTML::TokeParser::Simple, which makes it extremely easy to extract the src attribute from all <img> tags:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top