In the following string, I'd like to replace all BeginHello...EndHello
blocks that contain haha
by ''
:
s = """BeginHello
sqdhaha
fsqd
EndHello
BeginHello
1231323
EndHello
BeginHello
qsd
qsd
haha
qsd
EndHello
BeginHello
azeazezae
azeaze
EndHello
"""
This code:
import re
s = re.sub(r'BeginHello.*haha.*EndHello', '', s)
print s
does not work here: nothing is deleted.
How to use such a regex for a multiline pattern with Python re.sub
?