-1

I am trying to replace the double quotes " with a single quote ' in the below string.

("2016-09-28T09:08:45.812145","50.12"),("2016-09-28T09:09:45.969154","50.13"),("2016-09-28T09:10:45.926659","50.14")

How would I use a regex expression to do this?

anubhava
  • 761,203
  • 64
  • 569
  • 643
Lexus
  • 43
  • 1
  • 4
  • 1
    `str.replace(/\"/g, "'")` – adeneo Sep 28 '16 at 07:45
  • Have a look at this question: [Replacing all occurrences of a string in JavaScript](http://stackoverflow.com/questions/1144783/replacing-all-occurrences-of-a-string-in-javascript) – CloudPotato Sep 28 '16 at 07:45

1 Answers1

1

Here is one way you can do it:

var s = '("2016-09-28T09:08:45.812145","50.12"),("2016-09-28T09:09:45.969154","50.13"),("2016-09-28T09:10:45.926659","50.14")';

console.log(s.replace(/"/g,"'"));

Note that the regular expression is fairly simple, the only important point being the g modifier (which is the global modifier, as remarked by Wiktor Stribiżew), so all matches are detected and not just the first one.

Nadia Cerezo
  • 602
  • 5
  • 12
  • 1
    I'd avoid mixing up "greedy" and "global modifier". "Greedy" is used to describe quantifier behavior while `/g` just makes the regex engine advance its index upon a successful match to be able to find the next non-overlapping match. – Wiktor Stribiżew Sep 28 '16 at 07:47