Regex Example

Hex Color Pattern

Matches 3-digit and 6-digit hex color strings.

Regex Pattern

^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$

Test Cases

  • #fff - match
  • #12abef - match
  • #12abef44 - no match

Edge Cases

  • Does not include 8-digit alpha variants.
  • Requires the leading # symbol.