- No data uploaded
- Instant results
Regex for Hex Colour
Pattern: /#(?:[0-9a-fA-F]{3}){1,2}\b/g. Test it below and adapt it to your data — validation regexes are always a trade-off between strictness and real-world inputs.
Regex for Hex Colour
Matches/#(?:[0-9a-fA-F]{3}){1,2}\b/g
Brand #4f46e5, accent #FFF and #12345 (invalid).
| # | Match | Index | Groups |
|---|---|---|---|
| 1 | #4f46e5 | 6 | — |
| 2 | #FFF | 22 | — |
JavaScript (ECMAScript) regular expressions. Without the g flag only the first match is used by String.match — this tester always lists all matches.
Frequently asked questions
Is my data uploaded?
No. The calculation runs entirely in your browser — nothing you type is sent to a server.
Is it free?
Yes — free, unlimited and no sign-up.