in reply to Parsing string with tags
might Text::Balanced be what yuo are looking for?
PS
use strict; use warnings; use Text::Balanced qw(extract_tagged); my $str = '<tag0> word2 <tag1>word3 word4</tag1> word5 </tag0> word6 < +tag2>word7 word8</tag2> word9 <tag3>word10</tag3>'; # this leads to errors # my $str = 'BEFORE <tag0> word2 <tag1>word3 word4</tag1> word5 </tag0 +> word6 <tag2>word7 word8</tag2> word9 <tag3>word10</tag3> AFTER'; my @res = extract_tagged( $str , '<tag0>', '</tag0>'); foreach (qw(extracted remainder prefix opening included closing)){ my $res = shift @res // 'NA'; print "$_:\t$res\n"; } __END__ extracted: <tag0> word2 <tag1>word3 word4</tag1> word5 </tag0> remainder: word6 <tag2>word7 word8</tag2> word9 <tag3>word10</ta +g3> prefix: opening: <tag0> included: word2 <tag1>word3 word4</tag1> word5 closing: </tag0>
L*
|
|---|