You'd be better off treating this more as a parser problem than a regexp problem, because trying to match nested items in regexp is advanced stuff... here is some code that should get you started... not ideal but easy :)
$text = "<paragraph>some <paragraph>some data</paragraph>data</paragra
+ph><paragraph>more data</paragraph><paragraph>even more data</paragra
+ph>";
my $depth = 0;
$text =~ s{(<(/)?paragraph>)}{check($depth)}gie;
print "$text\n";
sub check {
if($2) {
$_[0]--;
if($_[0] == 0) {
return $1;
}
$_[0] = 0 if $_[0] < 0;
} else {
$_[0]++;
return $1 if $_[0] == 1;
}
return '';
}
- Ant
- Some of my
best work - (1 2 3)