0
so, if i do pattern = r"\." What i have done?
4 Respostas
+ 1
What you have done is escaped the special regular expression character '.' (Period) and will now be looking for just a period. Otherwise if this str is not used in a regex then it reads the string as raw which means it doesnt use the '\' special character. So it would appear exactly as "\."
+ 1
Not quite. If you are using this for regular expressions, the answer is this "\." will match with a period. If you would like to match a backslash and a period using regex then you would need to do this "\\\."
The backslash acts as an escape, meaning you use it to supress special regex characters such as the period, or even the backslash it self. Hence three backslashes, one to escape the backslash and one to escape the period.
0
oh. so if i put the r, it matches exactly a backslash and a dot, if i dont put the r, it matches a period, but in that case i dont need backslash? that is it?
0
thank you, now i understand!