// 匹配 0-255 ([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-5]{2})const colorReg = /(#[0-9A-Fa-f]{3,6}$)|(rgb(a)?(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-5]{2}),([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-5]{2}),([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-5]{2})(,(1|(0.[0-9]{2})))?))/;const colorTest = color => { console.log(color, ": ", colorReg.test(color));};colorTest("#333");colorTest("#345613");colorTest("#aaffee");colorTest("#afe");colorTest("#666666666");colorTest("#6");colorTest("rgb(1,2,3)");colorTest("rgba(255,255,255,0.75)");colorTest("rgba(125,225,255,0.73)");colorTest("rgba(255,255,666,0.75)");判断了 16 进制和 rgb,但感觉写的有点烦,不知道各位大佬们能不能帮忙优化一下



