2024-11-29 08:04:49
"RGB(125,125,125)".split(',').map((item)=>item.replace(/[^0-9]+/g,''))
// [125,125,125]
//使用正则匹配获取。
function extractRgbColorNumber2Array(rgbColorString){
var pattern = /^rgb\((\d+),(\d+),(\d+)\)$/gi;
var matched = pattern.exec(rgbColorString);
if(matched!==null){
var result = Array.prototype.slice.call(matched);
result.shift();
return result;
}
}
var data = extractRgbColorNumber2Array('rgb(23,222,145)');
console.log(data);
2024-11-29 08:16:49
我是先转数字组 在替换里面的字符串,
$data['color'] = explode(',', $data['color']);
$data['color'][0] = substr($data['color'][0], 4);
$data['color'][2] = str_replace(')','',$data['color'][2]);