I am trying to escape one or several of the following characters in a given string: ', " and \
I have attempted to do this with regular expressions, which works fine, but not in javascript seeing as how the engine is very limited feature-wise.
The problem is basically it needs to handle pre-escaped sequences. See examples below:
foo"bar ---> foo\"bar
foo\"bar ---> foo\"bar
foo\\"bar --> foo\\\"bar
foo\\\"bar -> foo\\\"bar
Etc. Same logic applies for the single quotes and backslashes too.
Can anybody point me in the right direction of how to acheive this in javascript?
Thanks in advance.