regex javascript to match both RGB and RGBA
It’s not so simple- an rgb is illegal with a fourth parameter. You also need to allow for percentage decimals as well as integer values for the rgb numbers. And spaces are allowed almost anywhere. function getRgbish(c){ var i= 0, itm, M= c.replace(/ +/g, ”).match(/(rgba?)|(\d+(\.\d+)?%?)|(\.\d+)/g); if(M && M.length> 3){ while(i<3){ itm= M[++i]; if(itm.indexOf(‘%’)!= -1){ itm= … Read more