title: Regex for matching CSS hex colors
body: <p>I'm trying to write regex that extracts all hex colors from CSS code.</p>
  
  <p>This is what I have now:</p>
  
  <p>Code:</p>
  
  <pre><code>$css = &lt;&lt;&lt;CSS
  
  /* Do not match me: #abcdefgh; I am longer than needed. */
  
  .foo
  {
      color: #cccaaa; background-color:#ababab;
  }
  
  #bar
  {
      background-color:#123456
  }
  CSS;
  
  preg_match_all('/#(?:[0-9a-fA-F]{6})/', $css, $matches);
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>Array
  (
      [0] =&gt; Array
          (
              [0] =&gt; #abcdef
              [1] =&gt; #cccaaa
              [2] =&gt; #ababab
              [3] =&gt; #123456
          )
  
  )
  </code></pre>
  
  <p>I don't know how to specify that only those colors are matched which ends with punctuation, whitespace or newline.</p>