I wouldn't try to do this using regular expressions but would use a state engine instead.
use strict; use warnings; use 5.010; my $string = q{TestVar(Test1->(xy))->Var2(Test2(10)(12))->Finalvar}; say $string; my $parenDepth = 0; my $newString = q{}; foreach my $char ( split m{}, $string ) { if ( $char eq q{(} ) { $parenDepth ++; } elsif ( $char eq q{)} ) { $parenDepth --; } else { $newString .= $char unless $parenDepth; } } say $newString;
The output
TestVar(Test1->(xy))->Var2(Test2(10)(12))->Finalvar TestVar->Var2->Finalvar
I hope this is helpful.
Cheers,
JohnGG
In reply to Re: Regex required to Replace the array specifiers in a string
by johngg
in thread Regex required to Replace the array specifiers in a string
by anandvn
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |