title: string to array, split by single and double quotes
body: <p>i'm trying to use php to split a string into array components using either <code>"</code> or <code>'</code> as the delimiter. i just want to split by the outermost string. here are four examples and the desired result for each:</p>
  
  <pre><code>$pattern = "?????";
  $str = "the cat 'sat on' the mat";
  $res = preg_split($pattern, $str);
  print_r($res);
  /*output:
  Array
  (
      [0] =&gt; the cat 
      [1] =&gt; 'sat on'
      [2] =&gt;  the mat
  )*/
  
  $str = "the cat \"sat on\" the mat";
  $res = preg_split($pattern, $str);
  print_r($res);
  /*output:
  Array
  (
      [0] =&gt; the cat 
      [1] =&gt; "sat on"
      [2] =&gt;  the mat
  )*/
  
  $str = "the \"cat 'sat' on\" the mat";
  $res = preg_split($pattern, $str);
  print_r($res);
  /*output:
  Array
  (
      [0] =&gt; the
      [1] =&gt; "cat 'sat' on"
      [2] =&gt;  the mat
  )*/
  
  $str = "the 'cat \"sat\" on' the mat 'when \"it\" was' seventeen";
  $res = preg_split($pattern, $str);
  print_r($res);
  /*output:
  Array
  (
      [0] =&gt; the
      [1] =&gt; 'cat "sat" on'
      [2] =&gt;  the mat
      [3] =&gt; 'when "it" was'
      [4] =&gt;  seventeen
  )*/
  </code></pre>
  
  <p>as you can see i only want to split by the outermost quotation, and i want to ignore any quotations within quotations.</p>
  
  <p>the closest i have come up with for <code>$pattern</code> is</p>
  
  <pre><code>$pattern = "/((?P&lt;quot&gt;['\"])[^(?P=quot)]*?(?P=quot))/";
  </code></pre>
  
  <p>but obviously this is not working.</p>