title: Parsing CSS by regex
body: <p>I'm creating a CSS editor and am trying to create a regular expression that can get data from a CSS document. This regex works if I have one property but I can't get it to work for all properties. I'm using preg/perl syntax in PHP.</p>
  
  <h3>Regex</h3>
  
  <pre><code>(?&lt;selector&gt;[A-Za-z]+[\s]*)[\s]*{[\s]*((?&lt;properties&gt;[A-Za-z0-9-_]+)[\s]*:[\s]*(?&lt;values&gt;[A-Za-z0-9#, ]+);[\s]*)*[\s]*}
  </code></pre>
  
  <h3>Test case</h3>
  
  <pre><code>body { background: #f00; font: 12px Arial; }
  </code></pre>
  
  <h3>Expected Outcome</h3>
  
  <pre><code>Array(
      [0] =&gt; Array(
              [0] =&gt; body { background: #f00; font: 12px Arial; }
              [selector] =&gt; Array(
                  [0] =&gt; body
              )
              [1] =&gt; Array(
                  [0] =&gt; body
              )
              [2] =&gt; font: 12px Arial; 
              [properties] =&gt; Array(
                  [0] =&gt; font
              )
              [3] =&gt; Array(
                  [0] =&gt; font
              )
              [values] =&gt; Array(
                  [0] =&gt; 12px Arial
                  [1] =&gt; background: #f00
              )
              [4] =&gt; Array(
                  [0] =&gt; 12px Arial
                  [1] =&gt; background: #f00
              )
          )
  )
  </code></pre>
  
  <h3>Real Outcome</h3>
  
  <pre><code>Array(
      [0] =&gt; Array
          (
              [0] =&gt; body { background: #f00; font: 12px Arial; }
              [selector] =&gt; body 
              [1] =&gt; body 
              [2] =&gt; font: 12px Arial; 
              [properties] =&gt; font
              [3] =&gt; font
              [values] =&gt; 12px Arial
              [4] =&gt; 12px Arial
          )
      )
  </code></pre>
  
  <p>Thanks in advance for any help - this has been confusing me all afternoon!</p>