RE: regex help

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Support Desk

    RE: regex help

    That’s it exactly..thx

    -----Original Message-----
    From: Reedick, Andrew [mailto:jr9445@A TT.COM]
    Sent: Tuesday, June 03, 2008 9:26 AM
    To: Support Desk
    Subject: RE: regex help

    The regex will now skip anything with an '@'in the filename on the
    assumption it's already in the correct format. Uncomment the os.rename line
    once you're satisfied you won't mangle anything.


    import glob
    import os
    import re


    for filename in glob.glob('*.ab ook'):
    newname = filename
    newname = re.sub(r'^[^@]+\.abook$', '@domain.com.ab ook', filename)
    if filename != newname:
    print "rename", filename, "to", newname
    #os.rename(file name, newname)


    -----Original Message-----
    From: Support Desk [mailto:mike@ipg lobal.net]
    Sent: Tuesday, June 03, 2008 10:07 AM
    To: Reedick, Andrew
    Subject: RE: regex help

    Thx for the reply,

    I would first have to list all files matching user.abook then rename
    them to
    user@domain.com .abook something like Im still new to python and haven't
    had
    much experience with the re module

    import os
    import re

    emails = os.popen('ls'). readlines()
    for email in emails:
    print email, '-->',
    print re.findall(r'\. abook$', email)



    -----Original Message-----
    From: Reedick, Andrew [mailto:jr9445@A TT.COM]
    Sent: Tuesday, June 03, 2008 8:52 AM
    To: Support Desk; python-list@python.org
    Subject: RE: regex help
    From: python-list-bounces+jr9445= att.com@python. org
    [mailto:python-list-bounces+jr9445= att.com@python. org]
    On Behalf Of Support Desk
    Sent: Tuesday, June 03, 2008 9:32 AM
    To: python-list@python.org
    Subject: regex help

    I am trying to put together a regular expression that will
    rename users address books on our server due to a recent
    change we made.  Users with address books user.abook need
    to be changed to user@domain.com .abook I'm having trouble
    with the regex. Any help would be appreciated.

    import re

    emails = ('foo.abook', 'abook.foo', 'bob.abook.com' , 'john.doe.abook ')

    for email in emails:
    print email, '-->',
    print re.sub(r'\.aboo k$', '@domain.com.ab ook', email)



    *****

    The information transmitted is intended only for the person or entity
    to
    which it is addressed and may contain confidential, proprietary, and/or
    privileged material. Any review, retransmission, dissemination or other
    use
    of, or taking of any action in reliance upon this information by
    persons or
    entities other than the intended recipient is prohibited. If you
    received
    this in error, please contact the sender and delete the material from
    all
    computers. GA623

Working...