I was not sure how to phrase the title of this question, but imagine i have the following string:
(1,2),(3,(4))
I want a regex that allows me to get 1,2
and 3,(4)
The regex I currently have is \\(([^)]*)\\)
.
The problem with this regex is that it gets me 1,2
and 3,(4
. This happens because it is matching the parenthesis of (4)
. But I need a regex that ignores the 4's parenthesis and only matches the outside ones, if that makes sense.
EDIT: to give more insight on the problem, this is the exact kind of string I expect: (STRING1,STRING2),(STRING3,STRING4)
where STRING
is a string of random characters (it can have letters, numbers, whitespaces, other random symbols). Since it has random characters, the strings themselves can have parenthesis, which will trigger the regex. I basically need to keep track of the every parenthesis found that I can ignore close parenthesis that match other open parenthesis.