I have the following string
mystr1 = \'mydirname\'
myfile = \'mydirname\\myfilename\'
I\'m trying to do this
newstr = re.su
In a regular expression, you can escape a backslash just like any other character by putting a backslash in front of it. This means "\\" is a single backslash.
You need a quadruple backslash:
newstr = re.sub(mystr1 + "\\\\", "", myfile)
Reason:
\\
"\\\\"
.Or you can use a raw string, so you only need a double backslash: r"\\"