title: Ignore certain characters in quotes
body: <p>I tried searching for the answer to this, but I couldn't find anything too helpful in this situation.  It's possible that I'm not searching the correct terms.</p>
  <p>I'm having trouble with this regex.  Consider this string:</p>
  <pre><code>$str = &quot;(1, 2, 'test (foo) bar'), (3, 4, '(hello,world)')&quot;;
  </code></pre>
  <p>I want to end up with a multidimensional array, like this:</p>
  <pre><code>$arr = array(
     array(1, 2, 'test (foo) bar'),
     array(3, 4, '(hello,world)')
  );
  </code></pre>
  <p>I figure I could run a regex to split it up separate strings like &quot;(1, 2, 'test (foo) bar')&quot; and &quot;(3, 4, '(hello,world)')&quot;, and then run a regex on each of those to split by comma, but as you can see my problem is the data has parentheses and commas in various strings, and I'd like to ignore those.</p>
  <p>So far I have this, which does the first part like I wanted, except if there are parentheses in the data, then it breaks.</p>
  <pre><code>preg_match_all('/\((.*?)\),?/', $str, $matches);
  </code></pre>
  <p>It gives me this:</p>
  <pre><code>Array
  (
      [0] =&gt; Array
          (
              [0] =&gt; (1, 2, 'test (foo)
              [1] =&gt; (3, 4, '(hello,world)
          )
  
      [1] =&gt; Array
          (
              [0] =&gt; 1, 2, 'test (foo
              [1] =&gt; 3, 4, '(hello,world
          )
  
  )
  </code></pre>
  <p>It truncates the data, naturally.  What can I do to ignore the parentheses that are in quotes?  If I can ignore them, then on the next step when I split each of these matches, I'll be able to ignore commas.</p>