For example input string:
s = "fo)o)fus()(bar((em)ro(em))dah((y(XXX)"
As a result I expect:
fus()((em)ro(em))dah(XXX)
It's like result should contain all "healthy" blocks, which has open "(" and closed ")" + "healthy" text between them. All sick parts should be removed: "fo)" and "o)" because they are not involved in "()" and they are not between "()" or are not included in "()"
One more example for check:
z = "))(OMG)123(()qwe(zxc)(ll"
should return
(OMG)123()qwe(zxc)
I will that it can be resolved as with re
module as regular script. But I have no idea which algorithm should be used.
PS: I will not refuse from any help. :)