How to delete a line with re?

Edwin.Madari at VerizonWireless.com Edwin.Madari at VerizonWireless.com
Mon Aug 18 08:56:44 EDT 2008


running this snippet, is blanking out ^abdc$.. what is the issue ?
abcd
efg
hijk
lmn
$

efg
hijk
lmn

regards
Edwin

-----Original Message-----
From: python-list-bounces+edwin.madari=verizonwireless.com at python.org
[mailto:python-list-bounces+edwin.madari=verizonwireless.com at python.org]
On Behalf Of Peng Yu
Sent: Sunday, August 17, 2008 11:47 PM
To: python-list at python.org
Subject: How to delete a line with re?


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),
--
http://mail.python.org/mailman/listinfo/python-list



The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure.  If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof.  Thank you.





More information about the Python-list mailing list