Skip to content

Instantly share code, notes, and snippets.

View kara-krzystan's full-sized avatar

Kara Krzystan Vallette kara-krzystan

  • Arizona, USA
View GitHub Profile
@kara-krzystan
kara-krzystan / regex-hex-values.md
Last active February 10, 2021 07:01
Computer Science for JavaScript: Regular Expressions

Regex Tutorial: How to Match a Hexadecimal Color Value

The purpose of this tutorial is to introduce you to regular expressions and demonstrate how they work. A regular expression, or regex, is a sequence of characters that illustrate or define a search pattern. They are used to find, match, replace, or validate input in strings. Regular expressions are used in many programming languages, my tutorial will focus on their use in JavaScript.

Summary

The following is the regular expression for matching a hexadecimal color value that we will be examining in this tutorial:

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