Looking for backslashes in square brackets and spaces in javascript string.
I have a line: (some string)and I need it to be\(some\ string\)
Now I am doing this:
x = '(some string)'
x.replace('(','\\(')
x.replace(')','\\)')
x.replace(' ','\\ ')
It works, but it is ugly. Is there a cleaner way to do this?
source
share