[New-bugs-announce] [issue18781] re.escape escapes underscore (Python 2.7)

Vajrasky Kok report at bugs.python.org
Mon Aug 19 17:05:40 CEST 2013

New submission from Vajrasky Kok:

$ ./python --version
Python 2.7.5+
$ ./python
Python 2.7.5+ (2.7:062533327ad2, Aug 19 2013, 22:44:52) 
[GCC 4.7.2 20121109 (Red Hat 4.7.2-8)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import re
>>> re.escape('_')

Python 3.3 and 3.4 got it right and don't escape the underscore.

Because many people are still doing their livelihoods with Python 2.7 and I am a compassionate person, here is the patch to fix the bug in Python 2.7.

components: Regular Expressions
files: dont_escape_underscore_in_regex_27.patch
keywords: patch
messages: 195638
nosy: ezio.melotti, mrabarnett, vajrasky
priority: normal
severity: normal
status: open
title: re.escape escapes underscore (Python 2.7)
type: behavior
versions: Python 2.7
Added file: http://bugs.python.org/file31373/dont_escape_underscore_in_regex_27.patch

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list