CSS RGB/RGBA Color
intermediateMatches CSS rgb() and rgba() color function syntax.
colorrgbcssdesign
Pattern
/rgba?\(\s*\d{1,3}\s*,\s*\d{1,3}\s*,\s*\d{1,3}(?:\s*,\s*(?:0|1|0?\.\d+))?\s*\)/giTry It
0 of 6 strings matched
Explanation
Matches rgb(R, G, B) or rgba(R, G, B, A) where R/G/B are 0-999 (no range validation) and alpha is 0-1 decimal.
Test Strings
Matching
- rgb(255, 0, 128)
- rgba(0, 0, 0, 0.5)
- RGB(100, 200, 50)
Non-matching
- #ff0000
- hsl(0, 100%, 50%)
- rgb(255 0 128)
Language Compatibility
| Language | Support |
|---|---|
| JS | Full support |
| PYTHON | Full support |
| JAVA | Full support |
| PHP | Full support |
| GO | Full support |
Code Snippets
const regex = /rgba?\(\s*\d{1,3}\s*,\s*\d{1,3}\s*,\s*\d{1,3}(?:\s*,\s*(?:0|1|0?\.\d+))?\s*\)/gi;
const text = "your text here";
const matches = text.match(regex);
console.log(matches);