Zend certified PHP/Magento developer

in python, how can i replace parentheses and text before it without touching the content inside? [migrated]

I want to convert this:
x = '3+sin(angle)*2'
to this:
x = '3+cosin(tan(angle))*2
the problem is that the angle is different every time.
I’ve tried “replace” and “re.sub” but can’t make this specific scenario happen.