in reply to Excluding groups of characters in regular expressions
$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 ''; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Excluding groups of characters in regular expressions
by semirhage (Initiate) on Dec 21, 2007 at 16:19 UTC | |
by suaveant (Parson) on Dec 21, 2007 at 19:52 UTC |