in reply to Matching HTML Tags
The hard part is dealing with nested tags, but if you start with the inside tags and work outwards, you have no real problems.use strict; use warnings; my $str = ' <x <y >>'; my $c = 0; my @arr; while ($str =~ /<[^<>]+>/) { $str =~ s/<([^<>]+)>/`$c`/; $arr[$c++] = $1; } s/ /"/ig for @arr; while ($str =~ /`\d+`/) { $str =~ s/`(\d+)`/<$arr[$1]>/g; } print $str;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Matching HTML Tags
by chas (Priest) on May 24, 2005 at 02:08 UTC |