Regular Expressions 101

Community Patterns

Community Library Entry

1

Regular Expression
ECMAScript (JavaScript)

/
^rgba?\((([+-]?\d+(\.\d+)?),\s*){2}[+-]?\d+(\.\d+)?(,\s*(0?\.\d|[01]))?\)$
/

Description

CSS RGB Color Regex for JS

  • Supports RGB and RGBA syntax (identical in CSS Color Module Level 4)
  • Well tested
  • Allows for decimal values
  • Currently does not support percentage values or CSS Color Module Level 4 white-space syntax
Submitted by anonymous - 5 years ago