$re = '/#[a-f0-9]{6}(?:,\s*#[a-f0-9]{6})?/';
$str = 'style=\\"color: rgb(255,0,24)\\"
style=\\"color: rgb(255, 0, 24)\\"
style=\\"color: rgba(255, 0, 24, .5)\\"
style=\\"color: hsla(170, 23%, 25%, 0.2 )\\"
style=\\"color: #fff\\"
style=\\"color: #f2ewq\\" this isn\\\'t a color
style=\\"color: #0f243e\\"
style=\\"color: #0f243e,#3f54ae\\"
style=\\"color: #0f243eпп\\" здесь кириллические буквы пропустило
style=\\"color: #0f243eбб,#3f54aeпп\\" здесь кириллические буквы пропустило
style=\\"color: 0x00ffff\\" This is a color with the `#` escaped
.foo{
color: rgb(255,0,24);
color: rgb(255, 0, 24);
color: rgba(255, 0, 24, .5);
color: hsla(170, 23%, 25%, 0.2 );
color: #fff;
color: rgba(#fff, .5) This shows it works with SASS
color: #f2ewq; this isn\\\'t a color
color: 0f243e;
color: #0f243e,#3f54ae;
color: 0x00ffff; This is a color with the `#` escaped
}';
preg_match($re, $str, $matches, PREG_OFFSET_CAPTURE, 0);
// Print the entire match result
var_dump($matches);
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for PHP, please visit: http://php.net/manual/en/ref.pcre.php