我有一个字符串可以是:
test = 'Something Else ( neW ) other and another (nEw ) with (nEw ) '
我需要得到:
result = 'Something Else other and another with '
但到目前为止我所取得的最好成绩是:
import re
f = re.findall(ur'\(\s*[nN][eE][wW]\s*\)',test)
for i in f: test = test.replace(i,'')
如何使用findall
来获取与搜索模式不匹配的字符串部分?
答案 0 :(得分:3)
re.sub
:
>>> import re
>>> test = 'Something Else ( neW ) other and another (nEw ) with (nEw ) '
>>> re.sub(r'\(\s*[nN][eE][wW]\s*\)','',test)
'Something Else other and another with '