Simply Hao on Mon, 26 Jun 2000 12:02:44 -0400 (EDT)


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: regex question


my $badhtml = <<'EOF';
...  just <A HREF="p2.html">click here</A> to <BR>continue  ...
...  we decided to <BR>leave town.<IMG SRC="foo.gif">  ...
...  today. <A HREF="tomorrow.html"<BR>>Tomorrow's agenda</A>  ...
...  <IMG SRC=<BR>"photo44.jpg">  ...
...  when you <A HREF="map.htm">visit the farm</A<BR>> you'll ...
EOF
my (@goodhtml, @stack);
my @tokens = split /([<>])/, $badhtml;
while (@tokens) {
    my $token = shift @tokens;
    next unless (defined $token && length $token);
    if ($token eq '<') {
        push @stack, '<';
    } elsif ($token eq '>') {
        pop @stack;
        next if @stack;
    }
    push @goodhtml, $token if @stack < 2;
}
print @goodhtml;

# Hao
**Majordomo list services provided by PANIX <URL:http://www.panix.com>**
**To Unsubscribe, send "unsubscribe phl" to majordomo@lists.pm.org**