Hex Color Code
beginnerMatches CSS hex color codes in 3, 4, 6, or 8 digit formats.
colorhexcssdesign
Pattern
/#(?:[0-9a-fA-F]{3,4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})\b/gTry It
0 of 8 strings matched
Explanation
Matches # followed by 3 digits (short RGB), 4 digits (short RGBA), 6 digits (full RGB), or 8 digits (full RGBA) of hexadecimal.
Test Strings
Matching
- #fff
- #FF5733
- #00ff0080
- #abcd
Non-matching
- #gg0000
- #12
- #1234567890
- FF5733
Language Compatibility
| Language | Support |
|---|---|
| JS | Full support |
| PYTHON | Full support |
| JAVA | Full support |
| PHP | Full support |
| GO | Limited support (ASCII-only word boundaries) |
Code Snippets
const regex = /#(?:[0-9a-fA-F]{3,4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})\b/g;
const text = "your text here";
const matches = text.match(regex);
console.log(matches);