fork download
  1. import re
  2. p = re.compile(r'(?:\B\W\s*)?\([^()]+\)')
  3. test_str = "(text9 & text10) & text1 & (\"text2\" | \"text3\" | \"text4\") & \"text5\" ! (text6 | text7 | text8)"
  4. print(p.findall(test_str))
  5.  
Success #stdin #stdout 0.01s 9016KB
stdin
Standard input is empty
stdout
['(text9 & text10)', '& ("text2" | "text3" | "text4")', '! (text6 | text7 | text8)']