I\'m trying to write regex that extracts all hex colors from CSS code.
This is what I have now:
Code:
$css = <<
Despite this question's age I'd like to ammend the following:
^#([[:xdigit:]]{3}){1,2}$
, where [[:xdigit:]]
is a shorthand for [a-fA-F0-9]
.
So:
[[:xdigit:]]{3}){1,2}$/", $css, $matches) ?>
Also noteworthy here is the usage of a non-capturing group (?>...)
, to ensure we don't store data in memory we never wanted to store in the first place.
Try it online