in reply to Regex For HTML Image Tags?

Unable to test right now, but this should work:
use HTML::Parser; HTML::Parser->new( default_h => [sub { print shift; }, "text"], start_h => [sub { my ($text, $tagname,$attr) = @_; return print $text unless $tagname eq "img"; if ($attr->{alt}) { print "[image: \"$attr->{alt}\"]"; } else { print "[image]"; } }, "text,tagname,attr"], )->parse(join "", <DATA>); __END__ <IMG SRC="foo"><BR> bar bar bar<BR> <IMG SRC="foo" alt="bar">

-- Randal L. Schwartz, Perl hacker

Replies are listed 'Best First'.
Re: Re: Regex For HTML Image Tags?
by hostile17 (Novice) on Mar 28, 2001 at 04:35 UTC
    Thank you all very much indeed. I appreciate it.

    I do know in my heart that I should use a module, but I also feel the need to wrestle with and write my own code, in order to learn...

    I'm going to write another more detailed question about the procedure I'm using, which I'm sure will give you all lots to laugh at.

    h17