in reply to Matching paired characters.

Regexp::Common has a regex to match balances parenthesis and brackets. You could use the module itself, or just grab the regex out of there. (It's $RE{balanced}{-parens}, if you're curious.)

Replies are listed 'Best First'.
Re: Re: Matching paired characters.
by gullcatcher (Initiate) on Jul 21, 2001 at 02:27 UTC
    Many thanks for responding.

    Perhaps I didn't set up the problem in a coherent manner.
    I am working on a program which involves compiling and executing auto-generated code
    At times, this auto-generated code is random code. This is all okay, but when the code is likely to
    branch, many instances of random-code raise exceptions, simply by virtue of a missing or extra curly bracket.

    Now here's the problem: before I eval the code, how do I check it, and if necessary, correct it?

    The eval code is constructed from a list of Perl statements, which may or may not contain a { or a }.
    Before the eval, the code needs to be checked and corrected.

    I've had a look at the Regexp::Common, though I am fairly sure that it can't correct the unbalanced parentheses in
    a list of statements. Am I a spanner - am I making a square wheel - or do I need to keep with this one?

    Many thanks,
    gullcatcher