Provide bulletproof RGB/RGBA regexp with css4 syntax support. You use capture groups matches to extract values.
RegExp | Color Space | Matches | Css Color Value |
---|---|---|---|
numberRGB | rgb |
rgb(255, 255, 255) |
<number>, <number>, <number> |
numberRGB | rgb |
rgb(.5, 25.5, 255.0) |
" " |
numberRGBA | rgba |
rgba(255, 25.5, 255, 1%) |
<number>, <number>, <number>, <alpha-value> |
numberRGBACss4 | rgba |
rgba(255, 25.5, 255, 1) |
" " |
percentRGB | rgb |
rgb(100%, 100.0%, .2%) |
<percent>, <percent>, <percent>, <alpha-value> |
percentRGB | rgb |
rgb(100%, 100.0%, .2) |
" " |
percentRGBA | rgba |
rgba(100%, 100.0%, 10%, .2%) |
" " |
percentRGBACss4 | rgba |
rgba(255 100.0 35 /.2%) |
<number> <number> <number> /<alpha-value> |
percentRGBACss4 | rgba |
rgba(100% 100.0% / .2) |
<percent> <percent> <percent> /<alpha-value> |
npm i https://github.com/simonpalepin/rgba-regexp.git
OR
yarn add https://github.com/simonpalepin/rgba-regexp.git
import { numRGBA, percentRGBA, numRGB, percentRGB, numRGBACss4, percentRGBACss4 } from '@simonpalepin/rgba-regexp';
if(numRGBA.test('rgb(255, 100, 20.5)')) {
...
}
Please don't hesitate