[docs] [issue12162] Documentation about re \number

Terry J. Reedy report at bugs.python.org
Sat May 28 23:59:27 CEST 2011


Terry J. Reedy <tjreedy at udel.edu> added the comment:

The doc consistently does NOT quote re's in the text. Rather, they are shaded gray, both in Windows help version and html version. So this one should not be treated differently.

Most of the confusion reported is due to not reading the intro paragraphs. I almost suggested closing this without action. However,  after saying to use the r prefix, the doc omits them from examples when not absolutely needed. In particular,

>>> m = re.search('(?<=-)\w+', 'spam-egg')

Why does \w work without being doubled or protected (and it does, I checked), while \1 does not? Hell if I know. So even though that example works, it should be changed. The doc should teach the rule "if strings contains '\', prefix with 'r'" rather than "test and add 'r' if it fails", or "learn the exact list of when needed", which is not given and unknown to me and most any beginner.

I advocate the same practice in the RE How To, which also has at least one example with '\' but without 'r':
>>> p = re.compile('\d+')

I do not think we need another example other than those in the text.

----------
keywords: +patch
nosy: +terry.reedy
stage:  -> needs patch
versions: +Python 2.7, Python 3.1, Python 3.2, Python 3.3

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


More information about the docs mailing list