The string can be like one of the following:
a(b,c)
a(a(b,c),d)
a(a(a(a(a(b,c),d),a(e,f)),g),h)
etc
I want to match an unlimited number of "a(x,y)". How can I do that using Regex? Here's what I have:
\\w\\(((?:\\([a-zA-Z0-9]+\\))|(?:[a-zA-Z0-9]+)),((?:\\([a-zA-Z0-9]+\\))|(?:[a-zA-Z0-9]+))\\)
It only matches up two recursions of "a(x,y)".
Java's standard regex lib does not support recursion, so you can't match such general nested constructs with it.
But in flavors that do support recursion (Perl, PCRE, .NET, etc) you can use expressions like:
\w+(?:\((?R)(?:,(?R))*\))?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With