Skip to content

Instantly share code, notes, and snippets.

View KyleKilmartin371's full-sized avatar

Kyle Kilmartin KyleKilmartin371

  • California
View GitHub Profile
@KyleKilmartin371
KyleKilmartin371 / colorRegex.md
Last active August 29, 2022 15:22
Regex for hex colors

Regex for hex colors

A Regex (regular Expression) is a snippet of code that is used to extract bits of information from any field of text. It accomplishes this by setting up key parameters to search for within a body of text. A regex is a very powerful tool and can be used in almost all programable languages like JavaScript, Java, VB, Python, and many more!

Summary

The regex that we will be looking at in this gist is for hex colors. A hex color is a representation of various colors that follows a specific hexadecimal integer count so it is fairly easy to keep track of. The regex to search for a hex color code will be: ^#([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$. Bellow we will break apart the different parts of this regex so that we can better understand what is being shown.

Table of Contents