🎨

RGB β†’ HEX

Master Tag
Tips & Tricks
Created
Sep 24, 2020 02:47 PM
Usage
Replace
Web Tags
Database
Formula
Alternatives
Cover
πŸ—„οΈ
Tip! Create spaces after each "R, G, B" NOT "R,G,B"
RegEx Example w/ RGB Converter
Name of Color
RGB
Convert to Hex
HEX
Convert to RGB
59, 34, 29
#3B221D
24, 98, 118
#186276
255, 0, 0
#FF0000
45, 84, 123
#2D547B
225, 42, 29
#E12A1D
57, 41, 21
#392915
0, 128, 0
#008000

How To Copy Formulas

  • Click inside cell
  • Click out (cell should be blue)
    • notion image
      Β 
  • Copy + Paste where desired
Β 

Tips With RegEx (Separating 3 Values In One Cell)

Remove

Remove First Number
replace(prop("RGB"), "[^,]*, ", "")
Remove Middle Number
replace(prop("RGB"), ",[^,]*", "")
Remove Last Number
replace(prop("RGB"), ",[^,]*$", "")

Isolate

Isolate First Number
replaceAll(replace(prop("RGB"), "(?:[^,]*, ){0}", ""), ",.*", "")
Isolate Second Number
replaceAll(replace(prop("RGB"), "(?:[^,]*, ){1}", ""), ",.*", "")
Isolate Third Number
replaceAll(replace(prop("RGB"), "(?:[^,]*, ){2}", ""), ",.*", "")

Calculate

Convert to HEX
"#" + replace(replace(replace(replace(replace(replace(format(floor(toNumber(replace(replace(prop("RGB"), ",[^,]*", ""), ",[^,]*$", "")) / 16)), "10", "A"), "11", "B"), "12", "C"), "13", "D"), "14", "E"), "15", "F") + replace(replace(replace(replace(replace(replace(format(toNumber(replace(replace(prop("RGB"), ",[^,]*", ""), ",[^,]*$", "")) / 16 % 1 * 16), "10", "A"), "11", "B"), "12", "C"), "13", "D"), "14", "E"), "15", "F") + replace(replace(replace(replace(replace(replace(format(floor(toNumber(replace(replace(prop("RGB"), "[^,]*, ", ""), ",[^,]*$", "")) / 16)), "10", "A"), "11", "B"), "12", "C"), "13", "D"), "14", "E"), "15", "F") + replace(replace(replace(replace(replace(replace(format(toNumber(replace(replace(prop("RGB"), "[^,]*, ", ""), ",[^,]*$", "")) / 16 % 1 * 16), "10", "A"), "11", "B"), "12", "C"), "13", "D"), "14", "E"), "15", "F") + replace(replace(replace(replace(replace(replace(format(floor(toNumber(replace(replace(prop("RGB"), "[^,]*, ", ""), "[^,]*, ", "")) / 16)), "10", "A"), "11", "B"), "12", "C"), "13", "D"), "14", "E"), "15", "F") + replace(replace(replace(replace(replace(replace(format(toNumber(replace(replace(prop("RGB"), "[^,]*, ", ""), "[^,]*, ", "")) / 16 % 1 * 16), "10", "A"), "11", "B"), "12", "C"), "13", "D"), "14", "E"), "15", "F")
Convert to RGB
format(toNumber(replace(replace(replace(replace(replace(replace(slice(replace(prop("HEX"), "#", ""), 0, 1), "A", "10"), "B", "11"), "C", "12"), "D", "13"), "E", "14"), "F", "15")) * 16 + toNumber(replace(replace(replace(replace(replace(replace(slice(replace(prop("HEX"), "#", ""), 1, 2), "A", "10"), "B", "11"), "C", "12"), "D", "13"), "E", "14"), "F", "15"))) + ", " + format(toNumber(replace(replace(replace(replace(replace(replace(slice(replace(prop("HEX"), "#", ""), 2, 3), "A", "10"), "B", "11"), "C", "12"), "D", "13"), "E", "14"), "F", "15")) * 16 + toNumber(replace(replace(replace(replace(replace(replace(slice(replace(prop("HEX"), "#", ""), 3, 4), "A", "10"), "B", "11"), "C", "12"), "D", "13"), "E", "14"), "F", "15"))) + ", " + format(toNumber(replace(replace(replace(replace(replace(replace(slice(replace(prop("HEX"), "#", ""), 4, 5), "A", "10"), "B", "11"), "C", "12"), "D", "13"), "E", "14"), "F", "15")) * 16 + toNumber(replace(replace(replace(replace(replace(replace(slice(replace(prop("HEX"), "#", ""), 5, 6), "A", "10"), "B", "11"), "C", "12"), "D", "13"), "E", "14"), "F", "15")))