Skip to content

Instantly share code, notes, and snippets.

@keberlea
keberlea / HexVal.md
Last active May 24, 2023 05:03
Regular Expressions

Matching a Hex value using regular expresssion (regex)

Welcome to this informative walkthrough on utilizing the following regular expression (regex) /^#?([a-f0-9]{6}|[a-f0-9]{3})$/ to match and validate hexadecimal color values. This guide will equip you with the knowledge and skills ot search for specfic colors or validate user input for color values. Discover how this regexn efficiently handles both three and six-character hexadecimal color formats, with or without the preceding '#' symbol. Wether you're a developer seeking to extract color codes from codebases or ensure valid color inputs from users, this walkthrough will provide step-by-step instructions and practical examples.

Get ready to harness the potential of this regular expression and enhance your color-related coding tasks.

Summary

In this walkthrough, we'll explore the regular expression /^#?([a-f0-9]{6}|[a-f0-9]{3})$/ and its application in matching and validating hexadecimal color values. This regex allows you to identify and ver