I want to strip double quotes from:
string = \'\"\" \" \" \"\"\\\\1\" \" \"\" \"\"\'
to obtain:
string = \'\" \" \" \"\"\\\
To remove the first and last characters, and in each case do the removal only if the character in question is a double quote:
import re
s = re.sub(r'^"|"$', '', s)
Note that the RE pattern is different than the one you had given, and the operation is sub
("substitute") with an empty replacement string (strip
is a string method but does something pretty different from your requirements, as other answers have indicated).