Make Regex.Split in between "..."

4

What regular expression do I use to get the comma character that is not within the "..." fields, eg:

line1, "line2", "hello,world", 215, X + Y
     ^        ^              ^    ^

I want to get only the referrals, I'm using the expression (?!.*"), but it does not work.

    
asked by anonymous 15.02.2016 / 01:06

2 answers

5

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.

    
15.02.2016 / 05:58
3

I've set up a REGEX other than #

  

Capture the previous group to identify the next comma.

REGEX:

(?|(['"])[^]+?(,)?|([^,])(,))

See it working .

The comma had also always been in the second group.

    
15.02.2016 / 11:44