Page 1 of 1

Regular expression help, splitting csv text lines

Posted: Fri Oct 14, 2011 10:24 am
by barry.marcus
Is there a way to split lines of comma-separated text into individual strings, except when the commas are somewhere between quotes? For example, given this line:

"test",a,20110101,"hello there, my friend",,b

I want to split it into these six strings:

"test"
a
20110101
"hello there, my friend"

b

Note that the empty strings are significant. After the split I'll strip all beginning and ending quotes from the individual strings. That I can handle! I just can't seem to figure out how to do the split.

As always, I appreciate your assistance.

Regular expression help, splitting csv text lines

Posted: Fri Oct 14, 2011 10:43 am
by John
There is a <split> command in Vortex which will do that.

Regular expression help, splitting csv text lines

Posted: Fri Oct 14, 2011 11:13 am
by mark
<split> won't handle the embedded , as desired. You'll need to use <timport> with "csv" to properly parse the csv.