[issue14221] re.sub backreferences to numbered groups produce garbage

2012-03-07 Thread Phillip Feldman
New submission from Phillip Feldman phillip.m.feld...@gmail.com: The first example below works; the second one produces output containing garbage characters. (This came up while I was creating a set of examples for a tutorial on regular expressions). import re text= The cat ate the rat.

[issue14221] re.sub backreferences to numbered groups produce garbage

2012-03-07 Thread Ezio Melotti
Ezio Melotti ezio.melo...@gmail.com added the comment: You forgot to use raw strings: text = The cat ate the rat. print(before: %s % text) before: The cat ate the rat. text = re.sub((\w+) ate the (\w+), r\2 ate the \1, text) print(after : %s % text) after : The rat ate the cat. (Maybe you