I have a list that contains some strings that have ‘\’ in them.
Ex:
'PEOPLE\\S BANK', 'PRIME MINISTER\\S'
I would like to add a single quote after every string that contains a \ in them.
Ive tried
import re
tt = re.sub(r'(\\)', r'\1"', str(updated_unique_accts))
This just adds a " between each . Any thoughts? There are multiple strings that contain this pattern.
Desired output
'PEOPLE\\'S BANK', 'PRIME MINISTER\\'S'
>Solution :
You’re very close, you just need to remember that both ' and " can be used for strings in python:
for line in updated_unique_accts:
tt = re.sub(r'(\\\\)', r"\1'", line)