How to delete a line with re?

Peng Yu PengYu.UT at gmail.com
Sun Aug 17 23:47:02 EDT 2008


Hi,

I want to delete the line with abc in the following program. But the
following program does not do what I want. Can somebody let me know
how to do it?

Thanks,
Peng

#!/usr/bin/python

import re

file="""abcd
efg
hijk
lmn
"""

regex = re.compile("^abcd$", re.MULTILINE)

print file,
print "$"
print regex.sub('', file),



More information about the Python-list mailing list