in reply to Regex to do a smart split()
outputsuse strict; my $line = join ",", ( '"completely quoted"', 'not quoted', 'partially "quoted"', '"completely quoted with embedded, comma"', 'partially "quoted with embedded, comma"', 'quote \'and comma, inside " single\' quote', 'single quote "and comma, inside of \' double" quote', 'last' ); my $re = qr/((?:[^"',]|"[^"]*"|'[^']*')+)/; print(">$_<\n") for $line =~ /$re/g;
it will choke on unbalanced quotes but it quick and dirty>"completely quoted"< >not quoted< >partially "quoted"< >"completely quoted with embedded, comma"< >partially "quoted with embedded, comma"< >quote 'and comma, inside " single' quote< >single quote "and comma, inside of ' double" quote< >last<
UPDATE
it will also choke on empty fields like
one,,three
--
flounder
|
|---|