Skip to content

Instantly share code, notes, and snippets.

View js-Quest's full-sized avatar

Jessica Saddington js-Quest

View GitHub Profile
@js-Quest
js-Quest / hexThis.md
Last active May 24, 2023 02:29
explanation of a regex for hex codes

What the Hex

A gist for explaining the regex used specifically for hex codes.

Summary

A Regex, also known as a Regular Expression, is a sequence of characters that specifies a matching pattern in text. It is considered a literal, so the pattern will always be wrapped in slash characters (/). In this gist we will be examining regexes and specifically the regex that matches hex values:

/^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/

A hex value, or hex code, is a six-character code preceded by a #. Sometimes a shorthand comprised of three charactes is used to represent the traditional six characters. In HTML it is used to represent colors. Using hex values is a written way of representing the amount of red, green, and blue in any particular shade of color, and it also visually represents the binary code of that specific color (since we aren't computers).

@js-Quest
js-Quest / WhatTheHex.md
Last active May 24, 2023 02:17
Explanation of a regex that matches a hex value

Regex Explained

What is a Regex?

A Regex, also known as a Regular Expression, is a sequence of characters that specifies a matching pattern in text. It is considered a literal, so the pattern will always be wrapped in slash characters (/). In this gist we will be examing the regex that matches hex values:

/^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/

Table of Contents