我正在尋找一些正則表達式來幫助解析我的CSV文件。CSV與數字的正則表達式
該文件具有
number,number
number,number
Comment I want to skip
number,number
number,number
防爆行:
319,5446
564425,87
Text to skip
27,765564
我讀每一行成一個字符串,我想用一些正規的快遞,以確保該行的模式匹配(號,數量)。如果沒有,那麼不要使用該行。
我正在尋找一些正則表達式來幫助解析我的CSV文件。CSV與數字的正則表達式
該文件具有
number,number
number,number
Comment I want to skip
number,number
number,number
防爆行:
319,5446
564425,87
Text to skip
27,765564
我讀每一行成一個字符串,我想用一些正規的快遞,以確保該行的模式匹配(號,數量)。如果沒有,那麼不要使用該行。
這裏是一個解決方案:
^\ d + \ d + $
這應該與你的號碼和線路開始/結束:
^\d+,\d+$
哪種語言做你想要做的這在? 在Perl中:
read in each line of the csv file and save to $line
if($line !~ m/\d+, \d+/) {
Do whatever you are going to do with the line with 2 numbers
}
在Java中使用this網站的幫助:
read in each line of the csv file and save to variable line
Pattern p = Pattern.compile("\d+, \d+"); // remove space if it isn't in file
Matcher m = p.matcher(line);
if (m.find()) {
//it matches
}
謝謝...讓我給它一個鏡頭。 – 2010-06-14 20:54:37
太棒了,效果很棒!謝謝。 – 2010-06-14 20:58:15