?Module re documentation bug, error, or misunderstanding?

Norman Shelley Norman_Shelley-RRDN60 at email.sps.mot.com
Fri Jul 26 16:34:45 EDT 2002


In   http://www.python.org/doc/current/lib/re-syntax.html  and even in my old
paper copy (version 1.5.2?) it has this:

\number
    Matches the contents of the group of the same number. Groups are numbered
starting from 1. For example, (.+) \1 matches  'the the' or '55 55', but not'the
end' (note the space after the group). This special sequence can only beused to
match one of the  first 99 groups. 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. (There is a group 0, which isthe entire
matched pattern, but it can't be referenced with \0; instead, use \g<0>.) Inside
the "[" and "]" of a character class, all numeric escapes are treated as
characters.

So, what am I missing below as both searches "should" succeed?

% python2.1
Python 2.1 (#2, Apr 24 2001, 11:33:06)
[GCC 2.95.3 20010315 (release)] on hp-uxB
Type "copyright", "credits" or "license" for more information.
>>> import re
>>> re.search("(.+) \1", '55 55')
>>>
>>> re.search("(.+) (.+)", '55 55')
<SRE_Match object at 40098328>





More information about the Python-list mailing list