|laziness, impatience, and hubris|
Regex: first match that is not enclosed in parenthesisby monkprentice (Novice)
|on Jun 30, 2013 at 09:13 UTC||Need Help??|
monkprentice has asked for the
wisdom of the Perl Monks concerning the following question:
Hi, suppose I have a term like this:
and I need to find the first occurrence of "+" that is not enclosed within parenthesis, i.e. the one before "5", how would I do that with a regular expression ?
I tried something like:$term =~ /((?:[^\+]|(?:\(.*\)))*)$_(.*)/
Which is supposed to mean:
What it actually does, is to stop at the first "+" it comes across.
I solved it now in a loop, but I was wondering if there was some elegant way to do it in a regular expression.
thanks in advance,