How do I match this with re
Christos TZOTZIOY Georgiou
tzot at sil-tec.gr
Thu Sep 4 18:57:45 CEST 2003
On 4 Sep 2003 09:35:18 -0700, rumours say that sjoshi at ingr.com (Sunit
Joshi) might have written:
>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'
>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
TZOTZIOY, I speak England very best,
Microsoft Security Alert: the Matrix began as open source.
More information about the Python-list