title: Too Many Characters Included in Attempt to Parse a CSV File
body: <h2>Background</h2>
  
  <p>I am attempting to parse a CSV file using PCRE regular expressions. That is, making out (or extracting) the various different "cells" available in the CSV, to then put them in a somewhat nicely organized array containing all the parts that the process of parsing managed to make out.</p>
  
  <p>The following regular expression is what I have come up with so far:</p>
  
  <pre><code>/(?:;|^)(?:(?:"(?:(?!"(;|$)).)*)|(?:([^;]*)))/g
  </code></pre>
  
  <p>I would highly recommend that you put this in a tester for regular expressions. Here is a slight bit of test data, that should match to a great extent.</p>
  
  <blockquote>
    <p><code>"There; \"be";"but; someone spoke";hence the young man;hence the son;"test;"</code></p>
  </blockquote>
  
  <h2>The Problem</h2>
  
  <p>The regular expression manages to extract the correct number of parts. It is meant for the regular expression to retrieve the text from inside each and every "cell" available in the CSV (use the CSV provided above for reference). It does to some extent.</p>
  
  <p>Here is the result of the groups in the regular expression above:</p>
  
  <blockquote>
    <p><code>"There; \"be</code><br>
    <code>;"but; someone spoke</code><br>
    <code>hence the young man</code><br>
    <code>hence the son</code><br>
    <code>;"test;</code></p>
  </blockquote>
  
  <p>As we can clearly see, the lines that are "escaped" using double-quotation marks include the <code>"</code> inside its group for the match, also selects the <code>"</code>, and sometimes even the semi-colon. From my understanding, the group for the negative lookahead should not include those.</p>
  
  <p>I have probably missed something very essential here. Perhaps someone can point me in the right direction towards a fix.</p>
  
  <h2>Edit and Potential Solution</h2>
  
  <p>It appears as though I might have managed to solve it. As opposed to what I said above, the negative lookahead does not actually appear to create a capture group, which I initially thought. As such, adding yet another group to the equation seems to parse out the segments I am after.</p>
  
  <pre><code>/(?:;|^)(?:(?:"((?:(?!"(;|$)).)*))|(?:([^;]*)))/g
  </code></pre>
  
  <p>I will, however, leave the question open for now, and will answer it myself if no other answer comes tumbling in. As not to make it opinion based, I would therefore further inquire as to whether there might be a more efficient way in terms of speed than that in which I am using above.</p>