Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Thanks in advance for your suggestion regards, --Buse Regexp::Common; use Cwd; use Regexp::Common::balanced; my $x = q(<extract> dfjklasjfdk jdflkasdjflkasd (1989) fdjsaflkajdf kkjdslkfjasdk <extract> dfsdlkfjdsa fdfadsfsad</extract> sajflksadjfklasd fkasdjfsadf Close</extract> <line> df adfjlkadf</line><extract> dfjalkdf akdjfklasdjflkadsjfasdclose1</extract>); my $e; my @ele = ('extract','line'); foreach $e (@ele) { while ($x=~/$RE{balanced}{-begin=>"<$e"}{-end=>"<\/$e>"}{-keep}/gs) { my $begin = "$1"; $x =~ s/($begin)/&$e($1,$e)/egsi; print "$x\n"; } } sub extract { my $a = $_[0]; my $tag = $_[1]; $a =~ s/<\/$tag>/<\/$tagæ>/gi; my @a=map(!/^(<e)/?("\n<e>".$_."<\/e>"):"\n".$_, split(/\n/,$a)); return "@a"; } sub line { my $a = $_[0]; my $tag = $_[1]; $a =~ s/<\/$tag>/<\/1$tag>/gi; my @a=map(!/^(<li)/?("\n<li>".$_."<\/li>"):"\n".$_, split(/\n/,$a)); return "@a"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Tag balanced with escape characters
by idsfa (Vicar) on Jul 27, 2005 at 14:17 UTC | |
|
Re: Tag balanced with escape characters
by tphyahoo (Vicar) on Jul 27, 2005 at 08:43 UTC | |
by Anonymous Monk on Jul 27, 2005 at 09:17 UTC | |
by tphyahoo (Vicar) on Jul 27, 2005 at 10:58 UTC |