const rgbString = "rgb(0, 163, 255)";
let matchResult = rgbString.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
console.log(matchResult + "\n");
delete(matchResult[0]);
for (let i = 1; i <= 3; i++) {
matchResult[i] = parseInt(matchResult[i]).toString(16);
if (matchResult[i].length == 1) {
matchResult[i] = '0' + matchResult[i];
}
}
const hexString ='#' + matchResult.join('').toUpperCase();
console.log(hexString);
/*
run:
rgb(0, 163, 255),0,163,255
#00A3FF
*/