0

I can't find general solution within tons of solutions. Just want to extract text outside any of parens group.

Ideally, this text

Application ( Change (Sui Generis (haha) ) cafe & laundrette) Monday to Thursday. (To match the sun).

match with 2 groups:

  • within parens: " Change (Sui Generis (haha) ) cafe & laundrette" and "To match the sun"

  • outside (at zero level) parens: "Application" + "Monday to Thursday."

Simple \(.*?\) or \(.*\) fails of course. I need to use non-capturing group I guess but how?

Peter.k
  • 1,475
  • 23
  • 40
  • 1
    If you need a regex solution it is [already posted here](https://stackoverflow.com/a/12280660/3832970). – Wiktor Stribiżew Feb 19 '19 at 11:09
  • Thanks. So I can use `print(result.captures('rec'))` to get phrases in parens but how to get the rest? I can't use `result.noncaptures('rec')` – Peter.k Feb 19 '19 at 11:18
  • 1
    There are several approaches: 1) split with that regex, 2) grab the indices of the parenthetical substrings and build the resulting list using them and the input string, 3) replace the matches once found with some text and then split with that text. – Wiktor Stribiżew Feb 19 '19 at 11:21
  • Ok. You helped me, thanks. – Peter.k Feb 19 '19 at 11:23

0 Answers0