This is my code right now,
import re
matches = re.search(r'^%s\s*\((.*?)\)'%"Hello", "Hello(Hi())")
print matches.group(1)
It gets everything inside the brackets after it see’s Hello.
So for example,
Hello(hi) produces hi
I’m having one problem,
Hello(Hi()) produces Hi( and not Hi()
Does anyone know how I could fix this issue by changing the regex?
If all you care about is what’s in the outermost parentheses, then use the
$anchor:If you want to match nested parentheses, that’s not possible with REs because your language will be context-free but not regular; instead, you can iteratively apply regexes to the result of regex matches.