New submission from Сергей Снегирёв: >>> path 'd:/\\temp\\\\' >>> pat = '[{}]+'.format(re.escape('\\/')) >>> re.sub(pat, '\\', path) Traceback (most recent call last): File "<pyshell#78>", line 1, in <module> re.sub(pat, '\\', path) File "C:\Users\Сергей\AppData\Local\Programs\Python\Python35\lib\re.py", line 182, in sub return _compile(pattern, flags).sub(repl, string, count) File "C:\Users\Сергей\AppData\Local\Programs\Python\Python35\lib\re.py", line 325, in _subx template = _compile_repl(template, pattern) File "C:\Users\Сергей\AppData\Local\Programs\Python\Python35\lib\re.py", line 312, in _compile_repl p = sre_parse.parse_template(repl, pattern) File "C:\Users\Сергей\AppData\Local\Programs\Python\Python35\lib\sre_parse.py", line 849, in parse_template s = Tokenizer(source) File "C:\Users\Сергей\AppData\Local\Programs\Python\Python35\lib\sre_parse.py", line 225, in __init__ self.__next() File "C:\Users\Сергей\AppData\Local\Programs\Python\Python35\lib\sre_parse.py", line 239, in __next self.string, len(self.string) - 1) from None sre_constants.error: bad escape (end of pattern) at position 0 >>> pat '[\\\\\\/]+' >>>
In JS it works: > 'd:/\\temp\\\\'.replace(new RegExp('[\\\\\\/]+', 'g'), '\\') "d:\temp\" ---------- components: Regular Expressions messages: 283626 nosy: ezio.melotti, mrabarnett, Сергей Снегирёв priority: normal severity: normal status: open title: re slashes versions: Python 3.5 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue29015> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com