2008-01-29 カテゴリ: Client Side タグ: Tips JavaScript Perl 正規表現 CSV 正規表現を使ったCSVパーサの続き。 トークン化したCSVを解釈するコードをJavaScriptとPerlで書いた。二つのロジックはほぼ同じ。 それぞれ、第一引数には解釈するCSVテキストを渡し、第二引数ではfield間の区切り文字を指定する。デフォルトはコンマ(,)。戻り値は、CSVを解釈した2次元配列(Perlの場合はリファレンス)。 function parseCSV(text, delim) { if (!delim) delim = ','; var tokenizer = new RegExp(delim + '|\r?\n|[^' + delim + '"\r\n][^' + delim + '\r\n]*|"(?:[^"]|"")*"', 'g');