New submission from becky lewis <bex.le...@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@python
components: Documentation
messages: 145911
nosy: becky.lewis, docs@python
priority: normal
severity: normal
status: open
title: re module doc has minor inaccuracy in character sets
versions: Python 2.7

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue13219>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to