Kent wrote: """The problem is that the re engine itself is interpreting the backslashes in the replacement pattern.
With a single slash you get a newline even though the slash is a literal in the replacement string: So if you want a literal \ in your replacement text you have to escape the \, even in a raw string: """ Thanks. will try to convince my colleague to use string formatting if he insists on regexp then he can do re.sub(r'(?i)<apppath>', apppath.replace('\\', '\\\\'), template) re.escape does not quite work for my example >>> re.sub(r'(?i)<apppath>', re.escape(apppath), template) 'C\\:\\napp\\_and\\_author\\_query\\napp\\_and\\_author\\_query\\a\\ b\\ c\\ d\\files' >>> print re.sub(r'(?i)<apppath>', re.escape(apppath), template) C\:\napp\_and\_author\_query\napp\_and\_author\_query\a\ b\ c\ d\files _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor