Hex Color Regex Validator | Shining Toolbox

Test hex color code regex patterns online. Validate #RGB and #RRGGBB color formats.

Quick Answer

Hex color regex: #(?:[0-9a-fA-F]{3}){1,2}\b. This matches both 3-character (#FFF) and 6-character (#FFFFFF) hex color codes.

Quick Template

Use the full Regex Tester

This variant is a fast preset. Open the full tool to fine-tune inputs, explore more options, and share the result.

Go to Regex Tester

Regex Tester

Test and debug regular expressions with live matching

//
Preview
Enter test string...

Quick Reference

. Any character
\d Digit [0-9]
\w Word char
\s Whitespace
^ Start of string
$ End of string
* 0 or more
+ 1 or more
? Optional
{n} Exactly n
[abc] Character set
(a|b) Group/Or

About Hex Color Regex Validator

How to Use the Regex Tester

  1. Enter your pattern - Type the regular expression
  2. Select flags - Choose matching behavior (global, case-insensitive, etc.)
  3. Enter test string - The text to match against
  4. Click Test - See matches highlighted in real-time
  5. Review results - View match details, positions, and groups

Regex Syntax Quick Reference

Character Classes

PatternMatches
.Any character (except newline)
\dDigit [0-9]
\DNon-digit
\wWord character [a-zA-Z0-9_]
\WNon-word character
\sWhitespace
\SNon-whitespace
[abc]Any of a, b, or c
[^abc]Not a, b, or c
[a-z]Character range

Quantifiers

PatternMatches
*0 or more
+1 or more
?0 or 1 (optional)
{3}Exactly 3
{3,}3 or more
{3,5}Between 3 and 5

Anchors

PatternMatches
^Start of string/line
$End of string/line
\bWord boundary
\BNon-word boundary

Groups & References

PatternDescription
(abc)Capture group
(?:abc)Non-capture group
(?<name>abc)Named group
\1Back-reference to group 1
`ab`

Common Regex Patterns

Email Address

[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}

URL

https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)

Phone Number

\+?[0-9]{1,4}?[-.\s]?\(?[0-9]{1,3}?\)?[-.\s]?[0-9]{1,4}[-.\s]?[0-9]{1,4}[-.\s]?[0-9]{1,9}

IP Address

\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b

Date (YYYY-MM-DD)

\d{4}[-/]\d{2}[-/]\d{2}

Hex Color

#(?:[0-9a-fA-F]{3}){1,2}\b

Flags Explained

FlagNameDescription
gGlobalFind all matches, not just the first
iCase-insensitiveIgnore case differences
mMultiline^ and $ match line boundaries
sDotall. matches newline characters
uUnicodeEnable full Unicode matching

Related Tools

Copied to clipboard!