Color RegEx

Published on Tue Mar 01 2022

Color RegEx

Additional matching regexes for
Color RegEx

Color RegEx

Color RegEx

html color match: transparent, #fff, #123456, rgb, rgba, hsl, hsla

This may be useful or not to test whether a given string is a valid (more or less) html color value. It matches color values such as: - #123 - short hex color value - #123456 - hex color value - rgb(255,255,0) - rgb color value - rgba(255,255,0,1.0) - rgba color value - hsl(360,100%,100%) - hsl color value - hsla(360,100%,100%,0.5334) - hsla color value Regex allows whitespaces between i.e. rgb and (, also between numbers and commas, but not in value like 55% between number and percentage. To change this behaviour simply remove \s*? from appriopriate places.

CSS Colors: RGB(A), HSL(A), HEX(3,4,6,8), var(--tw-color), etc...

Versatile, multiline matching of CSS colors of many common formats, including: - [x] HEX-3: `#123` (equivalent to `#112233`) - [x] HEX-4: `#FA0F` ( ... `#FFAA00FF`) - [x] HEX-6: `#FF3300` ( ...`#F30`) - [x] HEX-8: `#FFAA00FF` ( ...`#FA0F`) - [x] RGB: `rgb(0, 0, 0)` - [x] RGBA: `rgba(255, 255, 255, 1.0)` - [x] HSL: `hsl(100, 50%, 50%)` - [x] HSLA: `hsla(100, 20%, 20%, 1.0)` - [x] Vars: `var(--tw-color-name, #000000)` - [x] Misc: `color: inherit;` `color: currentColor;` `color: initial;`, etc. * With or without trailing semicolon or comma * Forgiving of whitespace issues * Allows property/declaration names (e.g. `color: #fff`), most other solutions do not.

Validate hex color

Validates hexadecimal color codes based on the following rule set: - Optionally starting with a hash. - 3 or 6 characters in length. - Using the [0-9a-f] character set.

HSL(A) Color Matching

This allows for both hsl and hsla color patterns to be matched. `hsla(50.5deg, .531%, .9%, 1.0)` - The hue can be matched without the word `deg`. - Hue is from 0-360 - Percentage allows for decimals. - Percentage is from 0-100% - Alpha is from 0.0-1.0

Discord emoji regex

Discod emoji regex

Regex Alamat

Regex untuk Alamat

Date Testing

Javascript date regex


regex for url

RegEx Workshop

Phone Number RegEx