I'm trying to find matching parentheses where there are also some more in the middle. I have the following regex that does that, it matches the parenthesis to find the one associated with it. What I need now is that it also searches a prefix for example "Test". It however recurses the entire pattern. I can't simply include "Test" in the start of the pattern. I also only want it to match when the prefix starts with "Test" and not just match any parentheses.
I want to replace the "Test( ... )" with something else, so it'd be preferable if it was one pattern so I can just use regex.sub()
.
import regex
# want to match 'Test(' prefix specifically
regex.search('\(([^()]|(?R))*\)', '... () ... Test(123, Test(123, (3), 3))')