[Python-bugs-list] [ python-Bugs-605436 ] Inconsistency in re docs
noreply@sourceforge.net
noreply@sourceforge.net
Thu, 05 Sep 2002 23:27:17 -0700
Bugs item #605436, was opened at 2002-09-06 02:27
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=605436&group_id=5470
Category: Python Library
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Christopher A. Craig (ccraig)
Assigned to: Nobody/Anonymous (nobody)
Summary: Inconsistency in re docs
Initial Comment:
>From the Library Reference (2.2.1):
\b Matches the empty string, but only at the
beginning or end of a
word. A word is defined as a sequence of
alphanumeric characters, so
the end of a word is indicated by whitespace or a
non-alphanumeric
character. Inside a character range, \b
represents the backspace
character, for compatibility with Python's string
literals.
Now reality:
Python 2.2.1 (#2, Apr 22 2002, 17:53:10)
[GCC 2.95.4 20011002 (Debian prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for
more information.
>>> import re
>>> t = re.compile(r'\bbag\b')
>>> t.search('test bag')
<_sre.SRE_Match object at 0x812aad0>
>>> t.search('test+bag')
<_sre.SRE_Match object at 0x815d528>
>>> t.search('test_bag')
>>> [ chr(i) for i in xrange(256) if not
t.search('test' + chr(i) +
'bag') ]
['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A',
'B', 'C', 'D',
'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
'P', 'Q', 'R',
'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '_', 'a', 'b',
'c', 'd', 'e',
'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
'q', 'r', 's',
't', 'u', 'v', 'w', 'x', 'y', 'z']
>>>
So the implementation appears to define a word as a
sequence of
alphanumeric characters or underscores, which means
either the
documentation, or the library is wrong. Now it happens
that this was
found while a friend of mine and I were looking to get
the exact
behavior that is implemented, so I'd prefer it if the
documentation
were updated to meet the implementation <.8 wink>.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=605436&group_id=5470