1

我已经尝试过 re.search 但不知道正则表达式的确切语法来替换(介于两者之间的任何内容)。假设有以下字符串:

D08838  Acotiamide hydrochloride hydrate (JAN/BBC); Acotiamide hydrochloride (USAN) Antagonist

我想得到这样的东西:

D08838  Acotiamide hydrochloride hydrate; Acotiamide hydrochloride  Antagonist
4

2 回答 2

0

我会去:

import re
s = 'D08838  Acotiamide hydrochloride hydrate (JAN/BBC); Acotiamide hydrochloride (USAN) Antagonist'
print re.sub('(\s*\(.*?\))', '', s)
#D08838  Acotiamide hydrochloride hydrate; Acotiamide hydrochloride Antagonist
于 2013-08-10T19:48:48.680 回答
0

这个怎么样:

>>> import re
>>> s = "D08838  Acotiamide hydrochloride hydrate (JAN/BBC); Acotiamide hydrochloride (USAN) Antagonist"
>>> re.sub('\s\([\w/]+\)', '', s)
'D08838  Acotiamide hydrochloride hydrate; Acotiamide hydrochloride Antagonist'
于 2013-08-10T19:46:49.877 回答