in reply to Determining if you have balanced delimiters

Your ARRRGH is correct. I believe your code will incorrectly pass the string "(()" because the second "(" qualifies for "." in the middle.

What you need is a dot that doesn't match any of your other items of interest. Perhaps (untested):

$middle = "(?:(?!$left|$right|$escape$left|$escape$right).)";

-- Randal L. Schwartz, Perl hacker

Replies are listed 'Best First'.
Re (tilly) 2: Determining if you have balanced delimiters
by tilly (Archbishop) on Nov 21, 2000 at 17:58 UTC
    No, it works. It was supposed to do that. :-)

    The idea is that it repeatedly matches a pair and removes it while it can. When it is done, it then checks if any were left over.

      Well, in that case, it's another problem, since the dot can match the escape character, so it'll incorrectly blast "(\)".

      I knew it was something. {grin}

      -- Randal L. Schwartz, Perl hacker

        Did you test it?

        It recognizes "(\)" as unbalanced. OTOH he *didn't* bother to have an escape escape an escape. So "(\\)" is still unbalanced.

        But that could be a question of definition, not a bug.