我有一个看起来像这样的字符串列表:
Item Q55127831 (Acute nitrobenzene poisoning with transient (optional) amino-aciduria.) > setting P921 to Q114953 (poisoning)
我要提取:
Acute nitrobenzene poisoning with transient (optional) amino-aciduria.
是否有内部括号(可选)。
我使用Python 3
我尝试了上面的Regex1和Regex2:
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给出:
Acute nitrobenzene poisoning with transient (optional
regExp2提供:
none
如果您有更合适的解决方案,可以帮忙吗?
谢谢