Possible Duplicate:
What exactly do “u” and “r”string flags in Python, and what are raw string litterals?
p = re.compile(r'(\b\w+)\s+\1')
p.search('Paris in the the spring').group()
What is the meaning of r
in the 1st line?
Possible Duplicate:
What exactly do “u” and “r”string flags in Python, and what are raw string litterals?
p = re.compile(r'(\b\w+)\s+\1')
p.search('Paris in the the spring').group()
What is the meaning of r
in the 1st line?
r
designates a raw string in Python, which has different rules than a standard string, such as you don't have to escape backslashes and other special chars.
From the re
documentation:
The solution is to use Python’s raw string notation for regular expression patterns; backslashes are not handled in any special way in a string literal prefixed with 'r'. So r"\n" is a two-character string containing '\' and 'n', while "\n" is a one-character string containing a newline. Usually patterns will be expressed in Python code using this raw string notation.