简体   繁体   English

正则表达式匹配和替换 " 为 '

[英]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.请注意,正则表达式相当简单,唯一重要的一点是g修饰符(这是全局修饰符,正如 Wiktor Stribiżew 所说),因此所有匹配项都会被检测到,而不仅仅是第一个匹配项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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