I have a string that can be:
test = 'Something Else ( neW ) other and another (nEw ) with (nEw ) '
I need to get:
result = 'Something Else other and another with '
But the best I've achieved so far is:
import re
f = re.findall(ur'\(\s*[nN][eE][wW]\s*\)',test)
for i in f: test = test.replace(i,'')
How to using findall
to get the part of the string NOT matching the searching pattern?
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 '
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.