Webflags: g

Hex Color Code

Match CSS hex color codes in both 3-digit (#RGB) and 6-digit (#RRGGBB) formats.

Try it in RegexPro

Pattern

regexJavaScript
/#(?:[0-9a-fA-F]{6}|[0-9a-fA-F]{3})\b/g

Raw source: #(?:[0-9a-fA-F]{6}|[0-9a-fA-F]{3})\b

How it works

Matches a # character followed by exactly 6 or exactly 3 hexadecimal digits. The \b word boundary prevents partial matches inside longer strings.

Examples

Input

#ff5733

Matches

  • #ff5733

Input

#abc

Matches

  • #abc

Input

#FFFFFF

Matches

  • #FFFFFF

Common use cases

  • CSS/SCSS color extraction
  • Design token parsing
  • Theme file analysis
  • Color palette generators
All patternsTest this pattern live →