Regular Expressions 101

Community Patterns

RGBA color values and opacity matcher

1

Regular Expression
ECMAScript (JavaScript)

/
^(?:rgba?)?[\s]?[\(]?[\s+]?(\d+)[(\s)|(,)]+[\s+]?(\d+)[(\s)|(,)]+[\s+]?(\d+)[(\s)|(,)]+[\s+]?([0-1]?(?:\.\d+)?)$
/
i

Description

Regex to match R-G-B and Opacity with/without "," and even RGBA text It will match rgba(x,x,x,x.x) rgba (x x X x.x) x,x,x,x.x x x x x.x

Submitted by Maulik Soni - 9 years ago