Suppose I have the following code (taken from Google's Python Class) which assists with pattern matching by checking if a piece of regex lies within a text
def Find(pat, text):
match=re.search(pat,text)
if match: print (match.group())
else: print('not found')
When I run Find(r'\n', '\\n')
, the function returns not found
.
From my understanding, the r
in r'\n'
removes the special meaning from the newline character, meaning that r'\n'
and '\\n'
are essentially identical strings. Why then, does the above function return not found
?