Problem with regular expression

Pieter Claerhout Pieter_Claerhout at CreoScitex.com
Wed Sep 27 07:08:28 EDT 2000


Hello all,

I'm trying to make a regular expression that looks like the following:

p = re.compile('[A-Za-z]:\\')
if p.match(filepath): return 'pc'

It looks right to me, but whenever I run the program, it fails with the following traceback:

Traceback (innermost last):
  File "C:\WINNT\Profiles\PCLAER~1\Desktop\PathTest.py", line 11, in ?
    print FileUtils.GetPathPlatform(path)
  File "C:\WINNT\Profiles\PCLAER~1\Desktop\FileUtils.py", line 119, in GetPathPlatform
    p = re.compile('[A-Za-z]:\\')
  File "d:\Python\Lib\re.py", line 79, in compile
    code=pcre_compile(pattern, flags, groupindex)
pcre.error: ('\\ at end of pattern', 10)

So it looks like we can't have a backslash at the end of a pattern. Is this true? If so, how can I work around that, as any type of character can go after the backslash, except for these characters:

\ / : * ? " < > |

Any ideas? Just worth mentioning: I'm (still) using Python 1.5.2...

Thanks,



Pieter




More information about the Python-list mailing list