Just another Perl shrine | |
PerlMonks |
Re: Regex problem while parsing tagged, hierarchical databy prasadbabu (Prior) |
on Sep 12, 2006 at 15:03 UTC ( [id://572551]=note: print w/replies, xml ) | Need Help?? |
Sivaraman, Also it is good to use Parser for these kind of works like jdtoronto and Fletch suggested. Though not efficient, here is my try in regex to match all <level2> inside <level1> $content =~s#(<level1 id=\"([^"]*)\"(?:(?!(?:<level1|$)).)*)(<level1)?#my $id = $2; my $level1 = $1; my $rest = $3; ($level1 =~ s|<level2>|<level2 id="$id">|g);$level1.$rest#egsi;update: sivaraman, immediately, i added '?' in (<level1)? after i posted. Sorry for not mentioning the updation in the node. Prasad
In Section
Seekers of Perl Wisdom
|
|