[Python-bugs-list] [ python-Bugs-599757 ] sub[n] not working as expected.

noreply@sourceforge.net noreply@sourceforge.net
Sat, 24 Aug 2002 15:14:57 -0700


Bugs item #599757, was opened at 2002-08-24 16:14
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=599757&group_id=5470

Category: Regular Expressions
Group: Python 2.2.1
Status: Open
Resolution: None
Priority: 5
Submitted By: Travis Shirk (nicfit)
Assigned to: Fredrik Lundh (effbot)
Summary: sub[n] not working as expected.

Initial Comment:
I'm running into what looks to be a bug in the python
2.2 re module.
These examples should demonstrate the problem.

Using Python 1.5.2:
import re;
data =
"\xFF\x00\xE0\xD3\xD3\xE4\x95\xFF\x00\x00\x11\xFF\x00\xF5"
data1 =
re.compile(r"\xFF\x00([\xE0-\xFF])").sub(r"\xFF\1", data);
print data1
'\377\340\323\323\344\225\377\000\000\021\377\365'


This output is exactly what I expect, but now see what
happens in 
2.2.1:
import re;
data =
"\xFF\x00\xE0\xD3\xD3\xE4\x95\xFF\x00\x00\x11\xFF\x00\xF5"
data1 =
re.compile(r"\xFF\x00([\xE0-\xFF])").sub(r"\xFF\1", data);
print data1
'\xFF\xe0\xd3\xd3\xe4\x95\xff\x00\x00\x11\xFF\xf5'

I like the hex output over the octal in 1.5, but the
substitution is
clearly wrong.  Notice each spot containing "\" in the
last result.


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=599757&group_id=5470