in reply to Regex required to Replace the array specifiers in a string

Doing nested parenthesis (or any paired delimiter) in regular expressions is not trivial. In your case, it is a little simpler since you are trying to strip out all parentheticals. You can accomplish your task by repeatedly running a substitution that eliminates inner-most pairs, like:

$_ = "TestVar(Test1->(xy))->Var2(Test2(10)(12))->Finalvar"; 1 while (s/\([^()]*\)//g); print;

I repeatedly substitute matched sets of parentheses to blank strings, where I ensure the parentheses do not contain other parentheses Using character classes. See perlretut for more info.

Replies are listed 'Best First'.
Re^2: Regex required to Replace the array specifiers in a string
by anandvn (Novice) on Jul 02, 2010 at 14:47 UTC
    Hi Utilitarian & Ken,

    Thanks a lot for your replies. My issue got resolved with your logic.

    Cheers
    Anand