|Just another Perl shrine|
Eternal question of parsing parenthesesby Anonymous Monk
|on Oct 24, 2009 at 12:59 UTC||Need Help??|
Anonymous Monk has asked for the
wisdom of the Perl Monks concerning the following question:
This must be a common question, but I can't find any answer.
In a string containing nested parentheses, I want to find the first parenthesis, in order to evaluate things for that before the rest. So for $_='a(b(c(d)(e))f)g(h)((i)j)'; the result should be b(c(d)(e))f.
This can be done the sad and boring way by splitting the string and going through it, counting parenthesis signs as you go. But surely there must be some clever regex to do it?
I came up with one solution, which looks wonderfully cryptic:
Is this a good idea? Can you improve it? Is there a better way?