han_perl has asked for the wisdom of the Perl Monks concerning the following question:

I can't figure out how to parse a variable with data like this:
$data = "129303(345)3453"
I'm trying to get the data, 345, in between the open and close braces ( ).
Does anyone know the solution to this?
  • Comment on how to parse character in between two braces ( ... )

Replies are listed 'Best First'.
Re: how to parse character in between two braces ( ... )
by BUU (Prior) on Jun 05, 2004 at 05:06 UTC
    /(\([^\)]+)\)/ This will, of course, blow up and try to eat you if you attempt use it to capture multiple parens, nested parens, parens that aren't balanced, etc, but it solves the stated problem.
Re: how to parse character in between two braces ( ... )
by CountZero (Bishop) on Jun 05, 2004 at 13:27 UTC
    Or use

    ($pre, $target, $post)= split /[()]/, $data;

    CountZero

    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law