Say I have a string - [H*la.Am!go]
and I want to replace all the characters specified in the character set with that character appended after "\"
Character set- ['_', '*', '[', ']', '(', ')', '~', '`', '>', '#', '+', '-', '=', '|', '{', '}', '.', '!','\']
So the output would be -
\\[H\\*la\\.Am\\!go\\]
I can go about doing this chaining replace() method like so:
str.replace('[','\\[').replace('_','\\_')...
But this searches the string repeatedly for characters, thereby inefficient and also the code isn't clean.
Could someone help me out in implementing the regex replacement for this please?