[Python-bugs-list] [ python-Bugs-542226 ] octal escape doc contradiction
noreply@sourceforge.net
noreply@sourceforge.net
Thu, 11 Apr 2002 05:25:30 -0700
Bugs item #542226, was opened at 2002-04-11 01:06
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=542226&group_id=5470
Category: Regular Expressions
Group: None
>Status: Closed
>Resolution: Fixed
Priority: 5
Submitted By: John Machin (sjmachin)
Assigned to: Fredrik Lundh (effbot)
Summary: octal escape doc contradiction
Initial Comment:
Python version 2.2.1, Library Reference, section
4.2.1
Following is old, correct
text:
\number
[snip]
If the first digit of number is 0, or
number is 3 octal digits long, it will not be interpreted as a group
match, but as the character with octal value number.
At the end
of the section, the following has been appended
recently:
"""Note that octal escapes are not included. While
the parser can attempt to determine whether a character is being
specified by it's ordinal value expressed in octal, doing so yields
an expression which is relatively difficult to maintain, as the
same syntax is used to refer to numbered groups. """
The first
sentence is quite incorrect; remove it.
>>>
re.sub("\157\157", "\165", "foobar")
'fubar'
>>>
The
second sentence would even if cleaned up and made correct would
still be out of place in this manual; remove it.
Also document
that octal numbers are interpreted modulo \400:
>>>
re.sub("\557\157", "\165", "foobar")
'fubar'
>>>
----------------------------------------------------------------------
>Comment By: Martin v. Löwis (loewis)
Date: 2002-04-11 14:25
Message:
Logged In: YES
user_id=21627
You are using plain Python strings here, not raw strings -
so the escape characters are used to form bytes in the
string already. The regular expression itself does not
contain a backslash:
>>> s="\557\157"
>>> ord(s[0])
111
>>> ord("\")
92
So the string s in this example definitely does not start
with a backslash. As a result, it does not demonstrate
whether re.sub supports octal escapes.
However, since re.sub does support octal escapes, I've
corrected the documentation in libre.tex 1.83.
----------------------------------------------------------------------
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=542226&group_id=5470