0

Can anyone tell me how to replace "{ with { using JavaScript?

Here is what I am trying to do:

string.replace(/\"\{/g, "{");
Boann
  • 48,794
  • 16
  • 117
  • 146
Ashish
  • 29
  • 2

2 Answers2

2

Your regex is fine. Don't forget that strings are immutable in javascript. The replace function doesn't change the receiver string but builds a new one.

So you must do

string = string.replace(/\"\{/g, "{");
Denys Séguret
  • 372,613
  • 87
  • 782
  • 758
0

In case you were using this directly on string you should use it on an instance of string. Not on string type.

(I know it sounds too trivial, but otherwise this code should have worked. :) )

var stringTypeVariable = 'some string "{ with target pattern';
var replacedVariable = stringTypeVariable.replace(/\"\{/g, "{");
BuddhiP
  • 6,231
  • 5
  • 36
  • 56