Last active
June 24, 2024 09:50
-
-
Save safareli/10603775 to your computer and use it in GitHub Desktop.
ported from java version http://stackoverflow.com/a/12457269/1798418
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var keywords_color_regex = /^[a-z]*$/; | |
var hex_color_regex = /^#[0-9a-f]{3}([0-9a-f]{3})?$/; | |
var rgb_color_regex = /^rgb\(\s*(0|[1-9]\d?|1\d\d?|2[0-4]\d|25[0-5])%?\s*,\s*(0|[1-9]\d?|1\d\d?|2[0-4]\d|25[0-5])%?\s*,\s*(0|[1-9]\d?|1\d\d?|2[0-4]\d|25[0-5])%?\s*\)$/; | |
var rgba_color_regex = /^rgba\(\s*(0|[1-9]\d?|1\d\d?|2[0-4]\d|25[0-5])%?\s*,\s*(0|[1-9]\d?|1\d\d?|2[0-4]\d|25[0-5])%?\s*,\s*(0|[1-9]\d?|1\d\d?|2[0-4]\d|25[0-5])%?\s*,\s*((0.[1-9])|[01])\s*\)$/; | |
var hsl_color_regex = /^hsl\(\s*(0|[1-9]\d?|[12]\d\d|3[0-5]\d)\s*,\s*((0|[1-9]\d?|100)%)\s*,\s*((0|[1-9]\d?|100)%)\s*\)$/; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note: the rgba regex only allows for a single digit precision for the alpha channel. Adding a
+
after(0.[1-9])
allows arbitrary precision. Updated value: