With Python re, it is not possible to just use a plain regex, you may use a replacement callback method inside re.sub.
If you want to remove all A inside (...) you may use
re.sub(r'\([^()]+\)', lambda x: x.group().replace('A', ''), s)
Here, \([^()]+\) matches (, 1+ chars other than ( and ), and then a ), passes the match value to the lambda expression (x) and the match text is accessible via m.group() (if you define capturing groups, you may access them usign .group(n)). With a mere replace('A', ''), you achieve what you need.
See the Python demo
The same can be done with a plain regex if you use PyPi regex module:
regex.sub(r'(?<=\([^()]*)A(?=[^()]*\))', '', s)
See this Python demo.
Here, the lookarounds are used, and this works because PyPi supports infinite-width lookbehinds.
re, but you may usere.sub(r'\([^()]+\)', lambda x: x.group().replace('A', ''), s)if you want to remove allAinside(...). The same can be done with just a regex if you use PyPi regex module,regex.sub(r'(?<=\([^()]*)A(?=[^()]*\))', '', s). - Wiktor Stribiżew\(([^()}+)\). In the callback just replace the a's then return the new string with paren's around it. Btw, don't use assertions, it will slow the regex down significantly. - user557597