unc = r'\\foo\bar' string1 = r'\\foo\bar' string2 = r'\\\\foo\\bar' if unc == string1: print "I wish to make a complaint" if re.match(string1, unc): print "Ello miss" if re.match(string2, unc): print "Sorry I have a cold"
I wish to make a complaint Sorry I have a cold
Seems the re.match operation re-escapes the literal string and so "Ello miss" never happens.
Can anyone explain why I have to re-escape the backslash where setting the string as a literal in the first place?
I want to keep a list of UNC paths in a configuration file and I'd prefer not to have to escape strings in that. While the comparator works, it would be useful to have a regex option available.