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
In reply to Re: Regex to do a smart split()
by flounder99
in thread Regex to do a smart split()
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |