New submission from Ezio Melotti <[EMAIL PROTECTED]>: The re module seems to treat the raw strings as normal strings: >>> 'a1a1a'.replace('1', r'\n') == re.sub('1', r'\n', 'a1a1a') False >>> 'a1a1a'.replace('1', '\n') == re.sub('1', r'\n', 'a1a1a') True In the first line str.replace and re.sub should perform exactly the same operation and return the same result but re.sub replaces the 1s with newlines, instead of a literal '\' and 'n'. The second line should evaluate to False but re.sub replaces again the 1s with newlines so the result is equal to the LHS.
>>> re.search(r'\n', 'a\na') <_sre.SRE_Match object at 0x00A81BF0> >>> r'\n' in 'a\na' False Searching a r'\n' in a string that contains a newline also return a result even if r'\n' is not in 'a\na'. Tested with Py2.5 on Linux and Py2.4/2.6 on win. The problem could be related to http://bugs.python.org/msg71861 Attached there is a txt file with more examples. ---------- components: Library (Lib), Regular Expressions files: raw-strings-with-re.txt messages: 75133 nosy: ezio.melotti severity: normal status: open title: re module treats raw strings as normal strings type: behavior versions: Python 2.4, Python 2.5, Python 2.5.3, Python 2.6 Added file: http://bugs.python.org/file11868/raw-strings-with-re.txt _______________________________________ 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