[New-bugs-announce] [issue30133] Strings that end with properly escaped backslashes cause error to be thrown in re.search/sub/etc. functions.

Patrick Foley report at bugs.python.org
Fri Apr 21 17:18:05 EDT 2017


New submission from Patrick Foley:

The following code demonstrates:

import re
text = 'ab\\'
exp = re.compile('a')
print(re.sub(exp, text, ''))

If you remove the backslash(es), the code runs fine.

This appears to be specific to the re module and only to strings that end in (even properly escaped) backslashes. You could easily receive raw data like this from freehand input sources so it would be nice not to have to remove trailing backslashes before running a regular expression.

----------
components: Regular Expressions
files: sample.py
messages: 292079
nosy: Patrick Foley, ezio.melotti, mrabarnett
priority: normal
severity: normal
status: open
title: Strings that end with properly escaped backslashes cause error to be thrown in re.search/sub/etc. functions.
versions: Python 2.7, Python 3.4
Added file: http://bugs.python.org/file46822/sample.py

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


More information about the New-bugs-announce mailing list