Re: How to delete a line with re?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Edwin.Madari@VerizonWireless.com

    Re: How to delete a line with re?

    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.m adari=verizonwi reless.com@pyth on.org
    [mailto:python-list-bounces+edwin.m adari=verizonwi reless.com@pyth on.org]
    On Behalf Of Peng Yu
    Sent: Sunday, August 17, 2008 11:47 PM
    To: python-list@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("^ab cd$", re.MULTILINE)

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




    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.


  • John Machin

    #2
    Re: How to delete a line with re?

    On Aug 18, 10:56 pm, Edwin.Mad...@Ve rizonWireless.c om wrote:
    running this snippet, is blanking out ^abdc$.. what is the issue ?
    abcd
    efg
    hijk
    lmn
    $
    >
    efg
    hijk
    lmn
    >
    The OP said he wanted to delete the line with abc [sic]. He showed no
    interest in "blanking out ^abdc$. [sic]". The given snippet deletes
    the abcd but doesn't delete the newline. However the OP gave no clue
    as to what the actual problem was -- he may have had a trailing space
    or two after the abcd in the input line; this would not be matched by
    the pattern and so nothing would be deleted.

    Comment

    Working...