This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: re.escape escapes underscore (Python 2.7)
Type: behavior Stage: resolved
Components: Regular Expressions Versions: Python 2.7
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: ezio.melotti Nosy List: ezio.melotti, mrabarnett, vajrasky
Priority: normal Keywords: patch

Created on 2013-08-19 15:05 by vajrasky, last changed 2022-04-11 14:57 by admin. This issue is now closed.

File name Uploaded Description Edit
dont_escape_underscore_in_regex_27.patch vajrasky, 2013-08-19 15:05 review
Messages (2)
msg195638 - (view) Author: Vajrasky Kok (vajrasky) * Date: 2013-08-19 15:05
$ ./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.
msg195640 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2013-08-19 15:18
This was considered a new feature when it was added in 3.2 (see #2650), so it was not backported to 2.7 because -- even if it was a minor change -- it was not 100% backward compatible.
Date User Action Args
2022-04-11 14:57:49adminsetgithub: 62981
2013-08-19 15:18:33ezio.melottisetstatus: open -> closed
messages: + msg195640

assignee: ezio.melotti
resolution: rejected
stage: resolved
2013-08-19 15:05:40vajraskycreate