Ezio Melotti <[EMAIL PROTECTED]> added the comment: My bad, I only checked with help(re.sub). In the examples with re.search I was indeed wrong because I forgot to escape the \ and for the regex engine \n is the same of n (whereas \\n is a literal \ followed by n), but I expected 'a1a1a'.replace('1', r'\n') to return the same of re.sub('1', r'\n', 'a1a1a') because the r'\n' is not a regex but a simple replacement string. Also, the doc says "repl can be a string or a function; if it is a string, any backslash escapes in it are processed. That is, \n is converted to a single newline character, \r is converted to a linefeed, and so forth.", this is the standard behavior of normal string, it should be mentioned that the backslashes are processed even if with raw strings and they need to be escaped with two \. I think that changing the behavior of what is supposed to be a "normal string" (the repl string) is not really a good idea (even if it's useful when you have things like '\1\n' and assuming that this is why it has different behavior), I'd rather prefer to use $1 instead of \1. Unlike '\1', (as far as I know) $1 has no special meaning in Python so there won't be any problem with raw strings.
_______________________________________ Python tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue4185> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com