function rgb2hex(sRGB) { // 去除 sRGB 的空格 const newSRGB = sRGB.replace(/\s+/g,""); // 定义 rbg 的正则表达式 const exp = /rgb\((0|1\d{0,2}|2[0-5]{2}),(0|1\d{0,2}|2[0-5]{2}),(0|1\d{0,2}|2[0-5]{2})\)/; // 若不符合规则,则返回原字符串 if (!exp.test(newSRGB)) return sRGB // 剔除 'rgb(' 和 ')', 剩下 'xx,xx...