[docs] [issue13219] re module doc has minor inaccuracy in character sets

becky lewis report at bugs.python.org
Wed Oct 19 16:14:40 CEST 2011


New submission from becky lewis <bex.lewis at gmail.com>:

The documentation for the re module  (specifically the section for []) states that:

"If you want to include a ']' or a '-' inside a set, precede it with a backslash, or place it as the first character."

However, after finding a typo in a regex I wrote it turns out to be false.

Using the following regex finds a match:
>>> regex = re.compile(r'[123ab-f-]+')
>>> regex.match('-')
<_sre.SRE_Match object at 0x8dd1b10>

I am not sure if this is an issue with the documentation or if the re module itself should not allow this behaviour. It would be nice if the documentation warned that hyphens (and other 'special' characters such as [) that are not escaped may still be matched, even though they are not the first character.

----------
assignee: docs at python
components: Documentation
messages: 145911
nosy: becky.lewis, docs at python
priority: normal
severity: normal
status: open
title: re module doc has minor inaccuracy in character sets
versions: Python 2.7

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue13219>
_______________________________________


More information about the docs mailing list