title: Split a comma delimited string which may contain commas and escaped quotes between single quotes
body: <p>How do you split a comma delimiter string. The string is a series of comma delimited numbers and words. Words are quoted with single quotes and numbers are not. Words may contain non-delimiting commas which should be fine inside quotes. Words may contain other kinds of quotes which must be escaped by a preceding backslash like so:</p>
  
  <pre><code>'','some-mail@some-domain.org','f4c1bfd5-969d-\'4,7\"2a-,b1\'29-42de49eb4406',2827,1378614418
  </code></pre>
  
  <p>I have tried to use a regex <code>[^\']</code> to split but that also picks up escaped commas.</p>
  
  <p>I have tried literally counting the characters as an alternative but that is deathly slow.</p>
  
  <p>Also python's <code>csv</code> reader splits the string on the non-delimiting commas if there are escaped slashes in the string. Perhaps it's not valid CSV?</p>
  
  <p>The sub-string list I should have as a result is:</p>
  
  <pre><code>[ 
  '', # empty string
  'some-mail@some-domain.org', # text like email
  'f4c1bfd5-969d-\'4,7\"2a-,b1\'29-42de49eb4406', # text, comma and escaped quotes
  2827, # number
  1378614418 # number
  ]
  </code></pre>
  
  <p>This is how I have used the csv module:</p>
  
  <pre><code>reader = csv.reader(StringIO(values_string), delimiter=',', quotechar="'", quoting=csv.QUOTE_ALL,skipinitialspace=True)
  </code></pre>
  
  <p>But I get:</p>
  
  <pre><code>['', 'some-mail@some-domain.org', 'f4c1bfd5-969d-\\4', '7\\"2a-', "b1\\'29-42de49eb4406'", '2827', '1378614418']
  </code></pre>