The big problem with this is that the regular expression parser doesn’t know what a quote opens and a quote closes. For example:
"line2", "hello,world"
"line2"
would be a group, ", "
would be another and "hello,world"
would be another, which would make it impossible to have 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, ie:
(("[\w\s,]*")(,)?)|([\w\s\+]*(,)?)
What do you mean:
Count everything inside quotes finished by 0 or 1 comma, or what has no quotes finished by 0 or 1 comma.
See here working.
Once this is done, the comma will always be in the second group and what should be really important for its application in the first.
Those that are not in quotes " "?
– gato
Yes, I want to take the commas that aren’t in quotes.
– CypherPotato
See if it helps:
(["'])(?:(?=(\\?))\2.)*?\1
– gato
That’s what’s picking up the fields
"..."
not the commas– CypherPotato