A renaissance view of technology

Regular expression for CSV files

After many hours of searching, I found this regular expression to work the best on parsing CSV files:

$expr = “/,(?=(?:[^\"]*\”[^\"]*\”)*(?![^\"]*\”))/”;

Example:

$matches = preg_split($expr, ‘2006-01-01, “Apples, Oranges, and Pears”, $5.95′);

1 Comment

rssComments RSS transmitTrackBack Identifier URI


Thanks! That worked perfectly :)

Comment by Braheem on April 23, 2008 4:48 pm

addLeave a comment