Monday, August 8, 2011

What's the difference between Regular String and Raw String in Python

In the Raw Strings prefixed with 'r', backslashes are not handled in any special way, so r"\n" literally means '\' and 'n', while "\n" means a newline character.
For example, the following regular expression pattern matches the C-like comment line
comment_re = re.compile(r""".*\\.*""")
comment_re = re.compile(""".*\\\\.*""")

No comments:

Post a Comment