import re
orig_line = '"aaa"|"bbb"|"123"|"!"\\"|"2010-01-04T00:00:01"'
new_line = re.sub(r'(?<=[^|])"(?=[^|])', '~', orig_line)
print(new_line)