简体   繁体   中英

Regex to Match and Replace " with '

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM