code goes below:
line = r'abc\def\n'
rline = re.sub('\\\\', '+', line) # then rline should be r'abc+def+n'
Apparently, I just want to replace the backslashes in line with ‘+’.
What I thought was that a backslash in line can be expressed as ‘\’, then why should I use ‘\\’ to get the re.sub work right.
I’m confused.
Because there are two levels of backslashing:
So
\\\\(python) ->\\(re.sub) ->\EDIT
And the SO level of backslashing! (it got me!)