[Python-bugs-list] Environment dependency in re parser (PR#290)
Tim Peters
tim_one@email.msn.com
Wed, 12 Apr 2000 22:30:46 -0400
> Full_Name: Nick Maclaren
> Version: 1.5.2
> OS: Irix 6.5
> Submission from: posh.mcc.wwwcache.ja.net (194.83.240.29)
>
>
> The following code works perfectly when used interactively:
>
> from re import match
>
> if match(r'"([^\"]|\?""|\\?)*"','"abc"') :
> print "Hello"
>
> When run non-interactively (e.g. 'python junk.py'), it fails:
>
> File "junk.py", line 3, in ?
> if match(r'"([^\"]|\?""|\\?)*"','"abc"') :
> File "/usr/local/Python-1.5.2/lib/python1.5/re.py", line 40, in match
> return _cachecompile(pattern, flags).match(string)
> File "/usr/local/Python-1.5.2/lib/python1.5/re.py", line 33, in
> _cachecompile
> value = compile(pattern, flags)
> File "/usr/local/Python-1.5.2/lib/python1.5/re.py", line 79, in compile
> code=pcre_compile(pattern, flags, groupindex)
> pcre.error: ('operand of unlimited repeat could match the empty
> string', 17)
It yields the same error for me whether run interactively or from file,
under the released 1.5.2 for Windows, here run from a DOS box:
D:\Python>python
Python 1.5.42 (#0, Jan 31 2000, 14:05:14) [MSC 32 bit (Intel)] on win32
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> from re import match
>>> if match(r'"([^\"]|\?""|\\?)*"','"abc"') :
... print "Hello"
...
Traceback (innermost last):
File "<stdin>", line 1, in ?
File "D:\Python\Lib\re.py", line 40, in match
return _cachecompile(pattern, flags).match(string)
File "D:\Python\Lib\re.py", line 33, in _cachecompile
value = compile(pattern, flags)
File "D:\Python\Lib\re.py", line 79, in compile
code=pcre_compile(pattern, flags, groupindex)
pcre.error: ('operand of unlimited repeat could match the empty string', 17)
>>>
The error msg is appropriate, since the third branch of the alternative
matches 0 or 1 backslashes, so the alternative as a whole can match the
empty string -- the error msg means exactly what it says. This is
functioning correctly as designed.
Perhaps you're using an interactive shell with a filter (readline?) that's
chewing up some of the backslashes itself?