I am studying regular expressions in an introduction course and I don't completely understand the use of raw strings. I will ilustrate my question with the most basic example:
Getting the same result that not using "r" before the regular expresion, Im confused of the use of "r".
Note: in other types of escapes as ''\n'', it does work as expected, impeding the escape and searching for the literal string "\n"
Quote:import reThe use of '"r'' before the regular expresion "\." should impede the escape of the backslash before the ".", therefore searching for any character except a newline (use of ''.'' in regular expressions), but it doesn't; The expression is still interpreted as a escape, searching for the caracter ''.''.
text = "This is a text with a dot."
pattern = r"\."
match = re.findall(pattern, text)
print(match)
Getting the same result that not using "r" before the regular expresion, Im confused of the use of "r".
Note: in other types of escapes as ''\n'', it does work as expected, impeding the escape and searching for the literal string "\n"