Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hex-color-regex

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hex-color-regex

The best regular expression (regex) for matching hex color values from string.

  • 1.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is hex-color-regex?

The hex-color-regex npm package is designed to provide a regular expression for matching hexadecimal color codes within strings. This is useful for validating and extracting hex color codes from text in web development and design tools.

What are hex-color-regex's main functionalities?

Validation of hex color codes

This feature allows you to validate whether a string is a valid hex color code. The regular expression checks for both shorthand (e.g., #FFF) and full (e.g., #FFFFFF) hex codes.

const hexColorRegex = require('hex-color-regex');
const regex = hexColorRegex();
console.log(regex.test('#1a1a1a')); // true
console.log(regex.test('#gggggg')); // false

Extraction of hex color codes

This feature allows you to extract all hex color codes from a given string. It is useful for parsing strings to retrieve all embedded color codes.

const hexColorRegex = require('hex-color-regex');
const text = 'Background color is #1a1a1a and border color is #00FF00.';
const matches = text.match(hexColorRegex());
console.log(matches); // ['#1a1a1a', '#00FF00']

Other packages similar to hex-color-regex

Keywords

FAQs

Package last updated on 03 Jun 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc