[issue42668] re.escape does not correctly escape newlines

2020-12-17 Thread Serhiy Storchaka
Change by Serhiy Storchaka : -- resolution: -> not a bug stage: -> resolved status: open -> closed ___ Python tracker ___ ___

[issue42668] re.escape does not correctly escape newlines

2020-12-17 Thread Martin Altmayer
Martin Altmayer added the comment: Thanks for the explanation, I did not know re.VERBOSE. I still think the behavior is a bit confusing, but it's probably not worth the effort to change this. -- type: behavior -> enhancement ___ Python tracker

[issue42668] re.escape does not correctly escape newlines

2020-12-17 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: > If the escape-result still contains a verbatim newline, why escape this > character at all? Because in verbose mode it is ignored. This is why \n and other ASCII whitespace characters, and '#', which starts a comment, should be escaped. '\\\n' and

[issue42668] re.escape does not correctly escape newlines

2020-12-17 Thread Matthew Barnett
Matthew Barnett added the comment: In a regex, putting a backslash before any character that's not an ASCII-range letter or digit makes it a literal. re.escape doesn't special-case control characters. Its purpose is to make a string that might contain metacharacters into one that's a

[issue42668] re.escape does not correctly escape newlines

2020-12-17 Thread Martin Altmayer
New submission from Martin Altmayer : 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