简体   繁体   English

Notepad ++正则表达式在每一行中找到一个“,”并用“。”替换奇数“,”

[英]Notepad++ regular expression find a “,” and replace odd “,” with “.” in every row

I ran into a mess recently with my data aquisition program which saves four datapoints separated by a comma(csv format) every couple of milliseconds. 最近我的数据采集程序遇到了麻烦,它每隔几毫秒就会保存四个以逗号(csv格式)分隔的数据点。 I used a PC (NL region) where the decimal point is a "," for data acquisition. 我使用PC(NL区域),其中小数点是“,”用于数据采集。

Now when i try to import my csv file to matlab/excel it gives me 8 columns (which should be 4) as all the decimals are also printed as "," 现在,当我尝试将我的csv文件导入matlab / excel时,它给了我8列(应该是4),因为所有小数也都打印为“,”

Is there a way to use regular expression in notepad++ (for eg) to find all "," in a row, and replace the odd ones to a "."? 有没有办法在记事本++中使用正则表达式(例如)连续查找所有“,”,并将奇数替换为“。”?

Thanks a lot for any help. 非常感谢您的帮助。 I have thousands of rows of data such that doing it manually will take ages. 我有数千行数据,因此手动操作需要很长时间。

Example raw data: 示例原始数据:
0,000000,293,625871,331,588659,37,440656 0,000000,293,625871,331,588659,37,440656
0,049000,294,148003,332,215504,37,400764 0,049000,294,148003,332,215504,37,400764
0,098000,294,814740,332,944775,37,261284 0,098000,294,814740,332,944775,37,261284
0,145000,295,683491,333,688803,37,184621 0,145000,295,683491,333,688803,37,184621
0,193000,296,504183,334,271264,37,058032 0,193000,296,504183,334,271264,37,058032
0,241000,297,213232,334,704293,37,109150 0,241000,297,213232,334,704293,37,109150
0,289000,297,595142,335,081749,37,113087 0,289000,297,595142,335,081749,37,113087
0,339000,297,968663,335,292896,37,088883 0,339000,297,968663,335,292896,37,088883
0,403000,298,204013,335,796915,37,109307 0,403000,298,204013,335,796915,37,109307

How the processed data should look: 处理后的数据应如何显示:
0.000000,293.625871,331.588659,37.440656 0.000000,293.625871,331.588659,37.440656
0.049000,294.148003,332.215504,37.400764 0.049000,294.148003,332.215504,37.400764
0.098000,294.814740,332.944775,37.261284 0.098000,294.814740,332.944775,37.261284
0.145000,295.683491,333.688803,37.184621 0.145000,295.683491,333.688803,37.184621
0.193000,296.504183,334.271264,37.058032 0.193000,296.504183,334.271264,37.058032
0.241000,297.213232,334.704293,37.109150 0.241000,297.213232,334.704293,37.109150
0.289000,297.595142,335.081749,37.113087 0.289000,297.595142,335.081749,37.113087
0.339000,297.968663,335.292896,37.088883 0.339000,297.968663,335.292896,37.088883
0.403000,298.204013,335.796915,37.109307 0.403000,298.204013,335.796915,37.109307

Just simply do: 只需简单地做:

Find what: (\\d+),(\\d+) 找到: (\\d+),(\\d+)
Replace with: $1.$2 替换为: $1.$2

Then clic on Replace all 然后clic on 替换所有

要匹配所有奇怪的逗号,请使用前面的断言,声明偶数个逗号:

 ,(?=(([^,]*,){2})*[^,]*$)

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

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