← Pattern Library PATTERN
Format · Code
/#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})\b/g
Format · Code Flags: g
Description
Matches CSS HEX color codes with 3 or 6 hexadecimal digits after the #. Values with non-hex characters or the wrong digit count, like #12g, are excluded. Used to extract colors from stylesheets.
Example Matches
#FFF
#1a2b3c
#00ff88
Test String
Background #1a2b3c, accent #FFF, invalid #12g
Open this pattern in the tester
Other Patterns