The big problem you want is that the regular expression parser does not know what a quotation mark is and what a date is. For example:
"line2", "hello,world"
"line2"
would be a group, ", "
would be another and "hello,world"
would be another, which would make a regular expression that solves everything. That is, you need to count the whole group, with or without quotation marks.
My suggestion is you count the commas together with each group, that is:
(("[\w\s,]*")(,)?)|([\w\s\+]*(,)?)
What do you mean:
Count all that is inside quotation marks ending with 0 or 1 commas, or what has no quotation marks ending with 0 or 1 commas.
See here working .
Once this is done, the comma will always be in the second group and what should really be important for your application in the first.