How can I effectively split multiline string containing backslashes resulting in unwanted escape characters into separate lines?
Here is an example input I'm dealing with:
strInput = '''signalArr(0)="ASCB D\axx\bxx\fxx\nxx"
signalArr(1)="root\rxx\txx\vxx"'''
I've tried this (to transform single backslash into double. So backslash escape would have precedence and following character would be treated "normally"):
def doubleBackslash(inputString):
inputString.replace('\\','\\\\')
inputString.replace('\a','\\a')
inputString.replace('\b','\\b')
inputString.replace('\f','\\f')
inputString.replace('\n','\\n')
inputString.replace('\r','\\r')
inputString.replace('\t','\\t')
inputString.replace('\v','\\v')
return inputString
strInputProcessed = doubleBackslash(strInput)
I'd like to get:
lineList = strInputProcessed.splitlines()
>> ['signalArr(0)="ASCB D\axx\bxx\fxx\nxx"','signalArr(1)="root\rxx\txx\vxx"']
What I got:
>> ['signalArr(0)="ASCB D\x07xx\x08xx', 'xx', 'xx"', 'signalArr(1)="root', 'xx\txx', 'xx"']