I have strings of this type:
text (more text)
What I would like to do is to have a regular expression that extracts the “more text” segment of the string. So far I have been using this regular expression:
"^.*\\((.*)\\)$"
Which although it works on many cases, it seems to fail if I have something of the sort:
text (more text (even more text))
What I get is: even more text)
What I would like to get instead is:
more text (even more text) (basically the content of the outermost pair of brackets.)
Besides lazy quantification, another way is:
In both regexes, there is a explicitly specified left parenthesis (
"\\(", with Java String escaping) immediately before the matching group. In the original, there was a.*before that, allowing anything (including other left parentheses). In mine, left parentheses are not allowed here (there is a negated character class), so the explicitly specified left parenthesis in the outermost.