0

我有一个字符串可以是:

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来获取与搜索模式不匹配的字符串部分?

4

1 回答 1

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  '
于 2013-08-04T10:12:09.517 回答