Hey guys,
I'm trying to use REGEX to get a recursive match on nested brackets. The examples I've found online match it, but don't group the values between the brackets. I can't think of a logical way of doing this.
For example:
(a(b(c)d)e) would return groups containing a,b,c,d,e
Example code is:
(\(((?>[^()]+)|(?1))*\))
The problem is that the conditional part means that the whole of (b(c)d) is matched as one. In way, I think the script needs to work like this:
1) find (c) (which is the only real match meeting the [()] part
2) look back and find the previous (, somehow storing the value between as a group
3) Look forward and find ), again storing the value between in a group
4) repeat until there are no complete sets of () left.
The problem with this arises if something like:
(a(b(c(d)(e))f)g)
Because then either (d) would be matched first.
Any thoughts?