你好,正则表达式专家们,
以前我从未遇到过无法用正则表达式优雅地仅用一步解决的字符串操作问题,直到现在。下面是我正在处理的示例数据:
0,"section1","(7) Delivery of 'certificate' outside the United States prohibited. Since both section 339 of the 1940 statute, 68/ and section 341 of the present law are explicit in their statement that the certificate shall be furnished the citizen, only if such individual is at the time within the United States, it is clear that the document could not and cannot be delivered outside the United States.",http://www.google.com/
1,"section2",,http://www.google.com/
2,"section3",",,",http://www.google.com/
这是一个更大的CSV文件的部分内容。我想使用一个正则表达式来替换所有出现在双引号内的逗号为下划线字符(_),不过重要的是要确保该正则表达式不会替换任何位于引号外部的逗号,因为那样会破坏CSV数据结构。
谢谢, Tom
--
澄清:
对不起,各位,我没有完全澄清我的问题,所以让我在下面概括一下:
- 假设在引号内的引号已经被转义(在Excel保存的CSV文件中,位于引号内的引号由""或"""等表示,所以它们可以事先轻松替换)。
- 我正在使用JavaScript。
使用上述示例文本,以下是进行正则表达式替换后应该看起来的样子(总共应该有5个替换):
证书只有在个人当前身处美国时,才能提供给公民。显然该文件无法并且无法在美国以外交付。",http://www.google.com/0,"section1","(7) Delivery of 'certificate' outside the United States prohibited. Since both section 339 of the 1940 statute_ 68/ and section 341 of the present law are explicit in their statement that the certificate shall be furnished the citizen, only if such individual is at the time within the United States, it is clear that the document could not and cannot be delivered outside the United States.",http://www.google.com/
1,"section2",,http://www.google.com/
2,"section3","__",http://www.google.com/
1,“第2节”,,http://www.google.com/
2,“第3节”,“__”,http://www.google.com/