title: How can I parse quoted CSV in Perl with a regex?
body: <p>I'm having some issues with parsing CSV data with quotes. My main problem is with quotes within a field. In the following example lines 1 - 4 work correctly but 5,6 and 7 don't.</p>
  
  <pre><code>COLLOQ_TYPE,COLLOQ_NAME,COLLOQ_CODE,XDATA
  S,"BELT,FAN",003541547,
  S,"BELT V,FAN",000324244,
  S,SHROUD SPRING SCREW,000868265,
  S,"D" REL VALVE ASSY,000771881,
  S,"YBELT,"V"",000323030,
  S,"YBELT,'V'",000322933,
  </code></pre>
  
  <p><strong>I'd like to avoid Text::CSV as it isn't installed on the target server</strong>. Realising that CSV's are are more complicated than they look I'm using a recipe from the Perl Cookbook.</p>
  
  <pre><code>sub parse_csv {
    my $text = shift; #record containg CSVs
    my @columns = ();
    push(@columns ,$+) while $text =~ m{
      # The first part groups the phrase inside quotes
      "([^\"\\]*(?:\\.[^\"\\]*)*)",?
        | ([^,]+),?
        | ,
      }gx;
    push(@columns ,undef) if substr($text, -1,1) eq ',';
    return @columns ; # list of vars that was comma separated.
  }
  </code></pre>
  
  <p>Does anyone have a suggestion for improving the regex to handle the above cases?</p>