Simple answer - probably not.
The first problem is a lack of a standard. While one may describe their csv in a way that is strictly defined, one cannot expect to get strictly defined csv files. "Be conservative in what you do, be liberal in what you accept from others" -Jon Postal
Assuming that one does have a standardesque that is acceptable, there is the question of escape characters and if these need to be balanced.
A string in many csv formats is defined as string value 1,string value 2. However, if that string contains a comma it is now "string, value 1",string value 2. If it contains a quote it becomes "string, ""value 1""",string value 2.
At this point I believe it is impossible. The problem being you need to determine how many quotes you have read and if a comma is inside or outside of the double quoted mode of the value. Balancing parentheses is an impossible regex problem. Some extended regular expression engines (PCRE) can deal with it, but it isn't a regular expression then.
You might find http://stackoverflow.com/questions/8629763/csv-parsing-with-a-context-free-grammar useful.
Amended:
I have been looking at formats for escape characters and haven't found any that need arbitrary counting - so that is probably not the issue.
However, there are issues of what is the escape character and record delimiter (to start with). http://www.csvreader.com/csv_format.php is a good read on the different formats in the wild.
- The rules for the quoted string (if it is a single quoted string or a double quoted string) differ.
**
'This, is a value' vs "This, is a value"
- The rules for escape characters
**
"This ""is a value""" vs"This \"is a value\""`
- The handling of embedded record delimiter ({rd})
** (raw embeded)
"This {rd}is a value" vs (escaped) "This \{rd}is a value" vs (translated)"This {0x1C}is a value"
The key thing here is that it is possible to have a string that will always have multiple valid interpretations.
The related question (for edge cases) "is it possible to have a invalid string that is accepted?"
I still strongly doubt that there is a regular expression that can match every valid CSV that is created by some application and reject every csv that cannot be parsed.
". Then the following is valid:"""this is a test.""",""– Spencer Rathbun Sep 27 '12 at 17:00