I am trying to extract all contents within outer paranthesis even if inner paranthesis is present. I used the following code
import re
s = "Text,Hei(Conductor (Opera), Conductor (Symphonic))"
l= re.findall(r'\((.*?)\)',s)
This gives ['Conductor (Opera', 'Symphonic']
But I need ['Conductor (Opera)', 'Conductor (Symphonic)']
CodePudding user response:
Try:
import re
s = "Text,Hei(Conductor (Opera), Conductor (Symphonic))"
l= re.findall(r'[( ]([A-Z][^)]*\))',s)
>>> l
['Conductor (Opera)', 'Conductor (Symphonic)']