in reply to Splitting a line on just commas
Easy peasy.
or$s = 'a,b,"hey, you","str1, str2, str3",end'; push @fields, $1 while $s =~ /("[^"]+"|[^",]+)(?:,|$)/g; print "$_\n" for @fields;
$s = 'a,b,"hey, you","str1, str2, str3",end'; @fields = $s =~ /("[^"]+"|[^,]+)(?:,|$)/g; # Use +, not *, or you get + a blank element print "$_\n" for @fields;
Both print:
a b "hey, you" "str1, str2, str3" end
|
|---|