Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > How do I match this with re

Reply
Thread Tools

How do I match this with re

 
 
Sunit Joshi
Guest
Posts: n/a
 
      09-04-2003
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
 
Reply With Quote
 
 
 
 
Terry Reedy
Guest
Posts: n/a
 
      09-04-2003

"Sunit Joshi" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> 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


 
Reply With Quote
 
 
 
 
Christos TZOTZIOY Georgiou
Guest
Posts: n/a
 
      09-04-2003
On 4 Sep 2003 09:35:18 -0700, rumours say that http://www.velocityreviews.com/forums/(E-Mail Removed) (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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
re.sub(): replace longest match instead of leftmost match? John Gordon Python 13 12-20-2011 02:58 AM
pat-match.lisp or extend-match.lisp in Python? ekzept Python 0 08-10-2007 06:08 PM
$match = true() for empty $match?? Victor XML 2 05-17-2004 10:43 AM
Java regex can't match lengthy match? hiwa Java 0 01-29-2004 10:09 AM



Advertisments