I am successfuly (almost) parsing a csv file using regex. This is a simple version of a more complex structure.
The (csv) text in cell b1 contains like:
c1,c2,c3;d1,d2,d3;e1,e2,e3;f1,f2,f3; (with a comma as field separator and ; as end of record)
To extract each of the data points, I use the following formula
c1 = REGEX(REGEX(b1, “[^;]+”,1), “[^,]+”,1) — first number is CSV row and second is CSV column
c2 = REGEX(REGEX(b1, “[^;]+”,1), “[^,]+”,2)
c3 = REGEX(REGEX(b1, “[^;]+”,1), “[^,]+”,3)
d1 = REGEX(REGEX(b1, “[^;]+”,2), “[^,]+”,1)
d2 = REGEX(REGEX(b1, “[^;]+”,2), “[^,]+”,2)
d3 = REGEX(REGEX(b1, “[^;]+”,2), “[^,]+”,3)
e1 = REGEX(REGEX(b1, “[^;]+”,3), “[^,]+”,1)
e2 = REGEX(REGEX(b1, “[^;]+”,3), “[^,]+”,2)
e3 = REGEX(REGEX(b1, “[^;]+”,3), “[^,]+”,3)
f1 = REGEX(REGEX(b1, “[^;]+”,4), “[^,]+”,1)
f2 = REGEX(REGEX(b1, “[^;]+”,4), “[^,]+”,2)
f3 = REGEX(REGEX(b1, “[^;]+”,4), “[^,]+”,3)
It works with a full data set. The problem occurs when a field in the csv data set is empty. This means that single commas are replaced by double commas when there is a blank csv field.
If there are empty fields in the csv, then the csv will have double commas. Regex in the current form no longer finds the (required) correct number of single commas in the csv which separates the data into the correct number of fields.
I have tried various regex versions, but can’t get it. I was hoping someone could help with a revised regex. Thank you in advance.
I need a Regex command which will find a double comma as two occurrences of a '[comma] and return an empty result.