How do I match this with re

Discussion in 'Python' started by Sunit Joshi, Sep 4, 2003.

  1. Sunit Joshi

    Sunit Joshi Guest

    Hello All
    I have a problem here where I need to find the drive letters in a text
    file and replace them with another letter. Now the lines can be as
    long as this

    6 'C:\pds\bddin64\report\mto\' 'SJOSHI'
    'D:\pds\bddin64\report\format\' 'SJOSHI'

    with multiple entries for path; i.e. there may be 2, as above or 1 or
    more then 2. If I use the expression .*'([A-Z]:).*?', it only matches
    the 2nd D: How do I get all the path groups ..??


    thanks
    Sunit
     
    Sunit Joshi, Sep 4, 2003
    #1
    1. Advertising

  2. Sunit Joshi

    Terry Reedy Guest

    "Sunit Joshi" <> wrote in message
    news:...
    > Hello All
    > I have a problem here where I need to find the drive letters in a

    text
    > file and replace them with another letter. Now the lines can be as
    > long as this
    >
    > 6 'C:\pds\bddin64\report\mto\' 'SJOSHI'
    > 'D:\pds\bddin64\report\format\' 'SJOSHI'
    >
    > with multiple entries for path; i.e. there may be 2, as above or 1

    or
    > more then 2. If I use the expression .*'([A-Z]:).*?', it only

    matches
    > the 2nd D: How do I get all the path groups ..??


    Use file.readline() or .readlines() and then process one line at a
    time.

    Terry
     
    Terry Reedy, Sep 4, 2003
    #2
    1. Advertising

  3. On 4 Sep 2003 09:35:18 -0700, rumours say that (Sunit
    Joshi) might have written:

    >Hello All
    >I have a problem here where I need to find the drive letters in a text
    >file and replace them with another letter. Now the lines can be as
    >long as this
    >
    >6 'C:\pds\bddin64\report\mto\' 'SJOSHI'
    >'D:\pds\bddin64\report\format\' 'SJOSHI'
    >
    >with multiple entries for path; i.e. there may be 2, as above or 1 or
    >more then 2. If I use the expression .*'([A-Z]:).*?', it only matches
    >the 2nd D: How do I get all the path groups ..??


    I assume that the drive letters will be directly after a single quote.
    You need this re:

    reDriveLetter = re.compile(r"(?<=')[A-Z](?=:\\)").

    You can try reDriveLetter.findall() or the reDriveLetter.finditer()
    functions then, each match object will match a single capital letter.

    Very important to everyone working with regular expressions: the
    redemo.py script. Search for a Scripts directory in your python
    directories (it's under Tools on Windows, otherwise get it from the
    source distribution), redemo.py is in there along with other useful
    scripts.
    --
    TZOTZIOY, I speak England very best,
    Microsoft Security Alert: the Matrix began as open source.
     
    Christos TZOTZIOY Georgiou, Sep 4, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. hiwa
    Replies:
    0
    Views:
    640
  2. Victor
    Replies:
    2
    Views:
    649
    Victor
    May 17, 2004
  3. ekzept
    Replies:
    0
    Views:
    376
    ekzept
    Aug 10, 2007
  4. John Gordon
    Replies:
    13
    Views:
    490
    Ian Kelly
    Dec 20, 2011
  5. Volkan Civelek

    Match doesn't match

    Volkan Civelek, Jul 19, 2006, in forum: Ruby
    Replies:
    4
    Views:
    168
Loading...

Share This Page