Regular Expressions 101

Community Patterns

CSS3 color expressions

1

Regular Expression
PCRE (PHP <7.3)

/
(?#https://regex101.com/r/eO8pP0/)(?(DEFINE)(?<hex>[a-fA-F\d])(?<hue>[+-]?(?:\d{1,8}(?:\.\d{0,8})?|\.\d{0,8}))(?<percent>(?:\d{1,2}|100)%)(?<channel>(?&percent)|25[0-5]|2[0-4]\d|[0-1]\d\d|\d{1,2})(?<rgb>\h*(?&channel)\h*(?:,\h*(?&channel)\h*){2})(?<hsl>\h*(?&hue)\h*(?:,\h*(?&percent)\h*){2})(?<alpha>1(?:\.0*)?|0?\.\d{1,8}|0))^(?:#(?:(?&hex){6}|(?&hex){3})|rgb\h*\((?&rgb)\)|hsl\h*\((?&hsl)\)|rgba\h*\((?&rgb),\h*(?&alpha)\h*\)|hsla\h*\((?&hsl),\h*(?&alpha)\h*\)|inherit|initial|transparent|unset|current[cC]olor|(?# Named colors)aliceblue|antiquewhite|aqua|aquamarine|azure|beige|bisque|black|blanchedalmond|blue|blueviolet|brown|burlywood|cadetblue|chartreuse|chocolate|coral|cornflowerblue|cornsilk|crimson|cyan|darkblue|darkcyan|darkgoldenrod|darkgray|darkgreen|darkgrey|darkkhaki|darkmagenta|darkolivegreen|darkorange|darkorchid|darkred|darksalmon|darkseagreen|darkslateblue|darkslategray|darkslategrey|darkturquoise|darkviolet|deeppink|deepskyblue|dimgray|dimgrey|dodgerblue|firebrick|floralwhite|forestgreen|fuchsia|gainsboro|ghostwhite|gold|goldenrod|gray|green|greenyellow|grey|honeydew|hotpink|indianred|indigo|ivory|khaki|lavender|lavenderblush|lawngreen|lemonchiffon|lightblue|lightcoral|lightcyan|lightgoldenrodyellow|lightgray|lightgreen|lightgrey|lightpink|lightsalmon|lightseagreen|lightskyblue|lightslategray|lightslategrey|lightsteelblue|lightyellow|lime|limegreen|linen|magenta|maroon|mediumaquamarine|mediumblue|mediumorchid|mediumpurple|mediumseagreen|mediumslateblue|mediumspringgreen|mediumturquoise|mediumvioletred|midnightblue|mintcream|mistyrose|moccasin|navajowhite|navy|oldlace|olive|olivedrab|orange|orangered|orchid|palegoldenrod|palegreen|paleturquoise|palevioletred|papayawhip|peachpuff|peru|pink|plum|powderblue|purple|red|rosybrown|royalblue|saddlebrown|salmon|sandybrown|seagreen|seashell|sienna|silver|skyblue|slateblue|slategray|slategrey|snow|springgreen|steelblue|tan|teal|thistle|tomato|turquoise|violet|wheat|white|whitesmoke|yellow|yellowgreen)$
/
igm

Description

Up to spec as of 2016-03-16. You can choose whether to enforce industry-standard casing for keywords via the "i" flag, which is enabled by default. Note that both "currentcolor" and "currentColor" are common; the relevant spec uses "currentColor", but several browsers prefer "currentcolor".

Submitted by Paul Buonopane @ NamePros - 8 years ago