regexp weirdness (bug?)

André Malo auch-ich-m at g-kein-spam.com
Tue Apr 5 15:44:10 EDT 2005


* Fredrik Lundh wrote:

> André Malo wrote:
> 
>> No, I suppose they shouldn't compile.
>> _re_pair should be (?P=plus).
> 
> the (?(NAME)RE|RE) form was added in 2.4.
> 
> looks like a bug to me; the "plus" group is set to "+" in all four cases,
> so the
> final pattern should match.  but I might be missing something...

Uh, yeah, I'm not up to date and still using 2.3 ;)
However, I've investigated a bit in the sre code and found this in
sre_compile.py:

   150          elif op is GROUPREF_EXISTS:
   151              emit(OPCODES[op])
   152              emit((av[0]-1)*2)
   153              skipyes = _len(code); emit(0)
   154              _compile(code, av[1], flags)

Sergey, can you please change line 152 in your sre_compile.py to

emit(av[0]-1)

and see if it works then? (The matcher also multiplies with 2, so this is
most likely the bug). But it's just theoretically, since I don't have
python 2.4 installed for a test :)

nd



More information about the Python-list mailing list