[New-bugs-announce] [issue18779] Misleading documentations and comments in regular expression about alphanumerics and underscore

Vajrasky Kok report at bugs.python.org
Mon Aug 19 09:45:16 CEST 2013


New submission from Vajrasky Kok:

According to:

http://oald8.oxfordlearnersdictionaries.com/dictionary/alphanumeric
http://en.wikipedia.org/wiki/Alphanumeric

Alphanumeric is defined as [A-Za-z0-9]. Underscore (_) is not one of them. One of the documentation in Python (Doc/tutorial/stdlib2.rst) differentiates them very clearly:

"The format uses placeholder names formed by ``$`` with valid Python identifiers
(alphanumeric characters and underscores).  Surrounding the placeholder with
braces allows it to be followed by more alphanumeric letters with no intervening
spaces.  Writing ``$$`` creates a single escaped ``$``::"

Yet, in documentations as well as comments in regex, we implicitely assumes underscore belongs to alphanumeric.

Explicit is better than implicit!

Attached the patch to differentiate alphanumeric and underscore in documentations and comments in regex.

This is important in case someone is confused with this code:
>>> import re
>>> re.split('\W', 'haha$hihi*huhu_hehe hoho')
['haha', 'hihi', 'huhu_hehe', 'hoho']

On the side note:
In Python code base, sometimes we write "alphanumerics" and "underscores", yet sometimes we write "alphanumeric characters" and "underscore characters". Which one again is the true way?

----------
assignee: docs at python
components: Documentation
files: fix_alphanumeric_and_underscore_doc_in_regex.patch
keywords: patch
messages: 195611
nosy: akuchling, docs at python, vajrasky
priority: normal
severity: normal
status: open
title: Misleading documentations and comments in regular expression about alphanumerics and underscore
versions: Python 3.3, Python 3.4
Added file: http://bugs.python.org/file31371/fix_alphanumeric_and_underscore_doc_in_regex.patch

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


More information about the New-bugs-announce mailing list