0

I have a list of strings that look like:

Item Q55127831 (Acute nitrobenzene poisoning with transient (optional) amino-aciduria.) > setting P921 to Q114953 (poisoning)

I want to extract:

Acute nitrobenzene poisoning with transient (optional) amino-aciduria.

Where there could be internal parenthesis (optional) or not.

I use Python 3

I tried with Regex1 and Regex2 above:

import re
regExp1 = "\(([^)]+)\)"
regExp2 = "\$\{((?:\{[^\{\}]*\}|[^\{\}]*)*)\}"
str = "Item Q55127831 (Acute nitrobenzene poisoning with transient (optional) amino-aciduria.) > setting P921 to Q114953 (poisoning)"
x = re.search(regExp2, str)[1,-1]
print(x)

regExp1 give:

Acute nitrobenzene poisoning with transient (optional

regExp2 give:

none

Could you help if you have more suitable solution?

Thanks

Xiiryo
  • 3,021
  • 5
  • 31
  • 48
  • For a regex solution: https://regex101.com/r/GMV4iD/1 –  Apr 18 '19 at 00:32
  • Thanks. It seems ok in regex101 but when I export a Python code or try it in my code it raise "error: invalid group reference 1 at position 28" or "none" if I remove the raw string r"xxx". – Xiiryo Apr 18 '19 at 08:38
  • Gosh, I hope 'regex101' is using the Python re module. Maybe you should contact them ~ –  Apr 18 '19 at 16:14

0 Answers0