I\'m trying to write regex that extracts all hex colors from CSS code.
This is what I have now:
Code:
$css = <<
The accepted answer shows you how to do it with regex, because that was your question. But you really don't need to use regex for this. Normally this is how I would do it:
if(ctype_xdigit($color) && strlen($color)==6){
// yay, it's a hex color!
}
for 100.000 iterations:
Regex solution *: 0.0802619457245 seconds
Xdigit with strlen: 0.0277080535889 seconds
*: hex: ([a-fA-F0-9]{6})