If you don't expect to be dealing with particularly long and complex strings, it should be sufficient to loop deleting contents from the inner parens outwards:
1 while $string =~ s/\([^(]*?\)//gs;
(Note that the simpler pattern s/\(.*\)// will not do the right thing on a string like "a(b)c(d)e", since it will remove the "c" as well. And you can't fix that by making the .* a minimal .*?, since that fails on nested parens.)
With long strings this approach will start to suffer from the need to repeatedly scan from the beginning of the string for each level of nesting, and then you may be better of with a solution that does a single pass over the string with Regexp::Common::balanced. However the additional complexity of the balanced paren matcher makes it a lot slower, so it won't be a win unless the string is really long or has parens nested quite deeply.
Hugo
In reply to Re: regular expression paranthesis remover
by hv
in thread regular expression paranthesis remover
by Kanishka
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |