Regular Expressions 101

RGB Colors in Hex Format: 3 or 6 Hexadecimal Digits

1

Regular Expression
ECMAScript (JavaScript)

/
^#([A-F0-9]{3}){1,2}$
/
igm

Description

Matches against RGB (not to be confused with RGBa). Will match against any and all RGB Hexadecimal Formatted colors. Some example of the values this regular expression was created to match are: "#FFFFFF", "#FFF", "#ABCDEF", "#123456", "#18F", "#812"

MUST USE THE 'i' FLAG (insensitive)

Without the i flag the regular expression will only match against colors formatted with all uppercase letters.

Submitted by jD3V - 2 years ago (Last modified 2 years ago)