Problem with regular expression

Arpad Kiss sekter at matavnet.hu
Wed Sep 27 13:28:45 CEST 2000


Hi,
Try this: p=re.compile(r'[A-Za-z]:\\')
Arpad

Pieter Claerhout <Pieter_Claerhout at CreoScitex.com> wrote in message
news:mailman.970053100.5550.python-list at python.org...
> 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