JSFiddle - React, Tailwind, and code Playground

by Sergey Aleshin

JavaScript

function componentToHex(c) {
    var hex = c.toString(16);
    return hex.length == 1 ? "0" + hex : hex;
}

function rgbtohex(r, g, b) {
    return "#" + componentToHex(r) + componentToHex(g) + componentToHex(b);
}
var /*----рег. выражение----*/
	string = 'rgb(255,255,255)',
	result = ( /\((.+)\)/.exec( string ) )[1].split(",");
    
document.write( result + '<br>') /*--строчка из рег. выражения----*/
document.write( rgbtohex( 0,0,0 ) + '<br>' );/*--rgb в hex--*/
document.write( rgbtohex( parseInt(result[0], 10), parseInt(result[1], 10), parseInt(result[2], 10) ) + '<br>'  ); /*-----РАБОТАЕТ (BloomerWD)-----------*/