Regular Expressions 101

Community Library Entry

1

Regular Expression
ECMAScript (JavaScript)

/
^(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9]), (25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9]), (25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$
/
gm

Description

There are several ways to format 24bit RGB Colors, however, two of the formats are far more common in the wild than others. The 2 most common 24bit RGB formats are

FORMATAlt NameNum Sys
RGB Hex FormatHexColorBase_16
RGB 256 FormatRGB ColorBase_10

<br>

This regex is for the RGB 256 Format, which should not be confused with the 8-bit 256-Colors standard, which was the most common color standard implemented by computers around the turn of the millennia. The RGB 256 Format, is a format used by the contemporary 24-bit True-Color standard. The HexColor format is also used for writing colors in human readable form, but it is generally preferred by technologies used in web development like CSS because its numeric system is human readable, but its also a good mathematical representation to use for writing colors. This is the "24-bit RGB 256 Color Format", if you want a pattern for matching 3 or 6 digit colors in HexColor format, use this pattern.

Submitted by anonymous - 3 years ago (Last modified 3 years ago)