I have to take a string from the user and format it so that it is acceptable for certain command line consumption. Basically, I need to replace any backslashes that come before a double quote (") with two back slashes. I can find the pattern using this regex:
import re
pattern = '\\\\+"'
string = "\\\\\\\" asdf \\\" \\ \\ \\\\\""
print string, "\n"
matches = re.findall(pattern, string)
But now that I have those matches, how do I replace them with double copies of themselves? So the 3 back slashes in front of a quote has to become 6, the 1 slash becomes 2, and the 2 becomes 4. The slashes that are not in front of quotes stay the same length.
Any advice on this would be greatly appreciated.
Thanks.