If there can be multiple sets of nested parentheses like "((foo) link)", I don't think this is possible with regular expressions. In particular, note that parentheses can be used inside URLs (such as at wikipedia), so there may still be nested parens even if the text itself doesn't contain any. So, in the general case I don't think this can be done with regex.
In order to solve it, I will assume you can have parentheses at most 1 level deep, and that no URLs contain parentheses.
The regex you're looking for is something like the following:
(\([^\)]*\)|[^\(<])*_link_
Where _link_
is a regular expression matching a link (which you describe in the problem statement, though it might need some tweaking). To summarize what that first part of my regex is: it matches 0 or more of either a parenthetical statement or a non-link non-parenthesis character. Now, use the matched back references (link.group(2)
in your example) to find your URL.