简体   繁体   English

替换Javascript字符串中的特定逗号

[英]Replace Specific Commas in Javascript String

I'm quite new to javascript and trying to learn by working on some scripts. 我对javascript很陌生,并尝试通过处理一些脚本来学习。 I'm pulling data from a CSV as a string ( attachments[k].getDataAsString(); ) which pulls in test results with a combination of numbers and text. 我正在从CSV中将数据作为字符串(annexs [k] .getDataAsString();)提取,该测试结果以数字和文本的组合形式提取测试结果。 I've done this several times before but the issue this time is that this report uses commas as the separator for thousands which causes breaks at the thousands when being imported into a Google Sheet. 我之前已经做过几次,但是这次的问题是该报告使用逗号作为千位分隔符,当导入Google表格时会导致千位中断。

Here's an example of what is currently being pulled: "completed (Percent) 这是当前被拉取的示例:“已完成(百分比)

Day,Total,,,,,"48,303",100.00%,"41,429",100.00%,"9,302",100.00%,"3,948",100.00%
Day,"Nov 11, 2014",,,,,"7,050",14.60%,"6,428",15.52%,"1,646",17.70%,698,17.68%"

There is a combination of numbers between "" and some between commas when there is no thousands separator. 如果没有千位分隔符,则“”之间会有一个数字组合,逗号之间有一些组合。

Is there a way to remove the comma for thousands separators and quotes across the string while keeping the remaining commas for the breaks? 有没有一种方法可以删除字符串中成千上万个分隔符和引号的逗号,同时保留其余的逗号分隔符?

Thanks! 谢谢!

You can use a regex of the form 您可以使用以下形式的正则表达式

"([^,]*),([^,]*)"

replace it with $1$2 将其替换为$1$2

For example: http://regex101.com/r/sW6jE7/1 例如: http : //regex101.com/r/sW6jE7/1

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

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