0

so, if i do pattern = r"\." What i have done?

18th Jul 2016, 7:57 PM
Benedek Máté Tóth
Benedek Máté Tóth - avatar
4 ответов
+ 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 "\."
19th Jul 2016, 1:21 AM
jj Fer
jj Fer - avatar
+ 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.
19th Jul 2016, 6:23 AM
jj Fer
jj Fer - avatar
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?
19th Jul 2016, 4:59 AM
Benedek Máté Tóth
Benedek Máté Tóth - avatar
0
thank you, now i understand!
19th Jul 2016, 2:52 PM
Benedek Máté Tóth
Benedek Máté Tóth - avatar