I have a string like this
This is\' it
I would like it to look like this
This is' it
Nothing I do seems to work
> "This is\' it".replace(/\\'/,"'");
'This is\' it'
> "This is\' it".replace("'",/\\'/);
'This is/\\\\\'/ it'
> "This is\' it".replace("\'","'");
'This is\' it'
> "This is\' it".replace("'","\'");
'This is\' it'
UPDATE: This is a little hard to wrap my head around but I had my example string inside an array something like.
> ["hello world's"]
[ 'hello world\'s' ]
It automatically happens like so:
> var a = ["hello world's"]
undefined
> a
[ 'hello world\'s' ]
> a[0]
'hello world\'s'
> console.log(a[0])
hello world's
undefined
> console.log(a)
[ 'hello world\'s' ]
undefined
>
None of your test strings actually contain backslashes. The string you are inputting each time is:
This is' itbecause the backslash escapes the single quote.Your first (regex-based) solution is almost perfect, just missing the global modifier
/\\'/gto replace all matches, not just the first. To see this in action, try the following: