Skip to content

Pattern matching and extracting color code formats using RegEx.

License

Notifications You must be signed in to change notification settings

Kyza/color-regex

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Color RegEx

Pattern matching and extracting color code formats using RegEx.

Written in Pomsky.

Support

<BlockComponent block={{"owner":"Kyza","repo":"blocks","id":"pomsky-viewer","type":"file"}} context={{"owner":"Kyza","repo":"color-regex","path":"full.pom","sha":"master","file":"README.md"}} height={500} />

Playground

Visualization

From https://regexper.com/.

Railroad graph of the regex.

Usage

It always matches 1, 3, 4, or 5 unnamed groups.

1

This group will be the name of the color alias such as red or papayawhip.

3-5

These groups are the color type, then the color values.

OR

These groups are "color", the color type, then the color values.

Usage

Just filter out the undefined values and you'll have an array of the values you want.

"rgb(255, 255, 255)".match(regex).filter((item, i) => i > 0 && item != null)
"color(display-p3 1 1 1 / 1)".match(regex).filter((item, i) => i > 0 && item != null)

Why?

For fun and to demonstrate Pomsky's power of making complex regular expressions that are still readable.

About

Pattern matching and extracting color code formats using RegEx.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published