tags:

views:

158

answers:

2

I'm looking for a regex that will parse a line at a time from a csv file. basically, what string.readline() does, but it will allow line breaks if they are within double quotes.

or is there an easier way to do this?

+3  A: 

Using regex to parse CSV is fine for simple applications in well-controlled CSV data, but there are often so many gotchas, such as escaping for embedded quotes and commas in quoted strings, etc. This often makes regex tricky and risky for this task.

I recommend a well-tested CSV module for your purpose.

--Edit:-- See this excellent article, Stop Rolling Your Own CSV Parser!

Mark Rejhon
A: 

The FileHelpers library is pretty good for this purpose.

http://filehelpers.sourceforge.net/

Robert Harvey