New submission from Martin Altmayer <martin.altma...@web.de>:
re.escape('\n') returns '\\\n', i.e. a string consisting of a backslash and a newline. I believe it should return '\\n', i.e. a backslash and an 'n'. If the escape-result still contains a verbatim newline, why escape this character at all? Note that Python's regular expressions engine allows newlines, so re.match(re.escape('\n'), '\n') gives a match. Thus, while this looks like an undesired behavior, it is not functionally broken. The same problem applies to some other characters: \t\r\v\f ---------- components: Regular Expressions files: test.py messages: 383237 nosy: MartinAltmayer, ezio.melotti, mrabarnett priority: normal severity: normal status: open title: re.escape does not correctly escape newlines type: behavior versions: Python 3.10, Python 3.7, Python 3.8, Python 3.9 Added file: https://bugs.python.org/file49689/test.py _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue42668> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com