title: Splitting comma separated string, ignore commas in quotes, but allow strings with one double quotation
body: <p>I have searched through several posts on stackoverflow on how to split a string on comma delimiter, but ignore splitting on comma in quotes (see: <a href="https://stackoverflow.com/questions/4982542/how-do-i-split-a-string-into-an-array-by-comma-but-ignore-commas-inside-double-qu">How do I split a string into an array by comma but ignore commas inside double quotes?</a>) I am trying to achieve just similar results, but need to also allow for a string that contains one double quote. </p>
  
  <p>IE. Need <code>"test05, \"test, 05\", test\", test 05"</code> to splits into</p>
  
  <ul>
  <li><code>test05</code></li>
  <li><code>"test, 05"</code></li>
  <li><code>test"</code></li>
  <li><code>test 05</code></li>
  </ul>
  
  <p>I tried a similar method to one mentioned here: </p>
  
  <p><a href="https://stackoverflow.com/questions/366202/regex-for-splitting-a-string-using-space-when-not-surrounded-by-single-or-double">Regex for splitting a string using space when not surrounded by single or double quotes</a></p>
  
  <p>Using Matcher, instead of <code>split()</code>. however, that specific examples it splits on spaces, and not on commas. I've tried to adjust the pattern to account for commas, instead, but have not had any luck.</p>
  
  <pre><code>String str = "test05, \"test, 05\", test\", test 05";
  str = str + " "; // add trailing space
  int len = str.length();
  Matcher m = Pattern.compile("((\"[^\"]+?\")|([^,]+?)),++").matcher(str);
  
  for (int i = 0; i &lt; len; i++)
  {
      m.region(i, len);
  
      if (m.lookingAt())
      {
          String s = m.group(1);
  
          if ((s.startsWith("\"") &amp;&amp; s.endsWith("\"")))
          {
              s = s.substring(1, s.length() - 1);
          }
  
          System.out.println(i + ": \"" + s + "\"");
          i += (m.group(0).length() - 1);
      }
  }
  </code></pre>