Recursive reference but part not recursive

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
redneb
Forum Newbie
Posts: 2
Joined: Mon Dec 20, 2010 10:39 pm

Recursive reference but part not recursive

Post by redneb »

Hey guys, I am trying to capture stuff inside the parentheses. The problem is that it is possible for parentheses to be inside the sqrt.
example string: "sqrt(5^(x+3)-7)"
desired output capture: 5^(x+3)-7
desired output: sqrt{5^(x+3)-7}
The following captures the correct part but it doesn't work if you put sqrt before it.
/\((?:[^()]+|(?R))*\)/

For reference: http://php.net/manual/en/regexp.reference.recursive.php
redneb
Forum Newbie
Posts: 2
Joined: Mon Dec 20, 2010 10:39 pm

Re: Recursive reference but part not recursive

Post by redneb »

I got it.
sqrt(\((?:[^()]++|(?1))+\))
Post Reply