This regex pattern matches a hex color value that starts with a '#' followed by either 3 or 6 characters that can be any combination of letters A-F (uppercase or lowercase) and numbers 0-9.
const regex = /#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})/;
const color = '#1a2B3c';
console.log(color.match(regex));
Kopieren