Created
August 18, 2020 10:23
-
-
Save KouroshAlinaghi/63b626582ae665224c9a2e55e60c4b8a to your computer and use it in GitHub Desktop.
Regex for some common color code formats (for ruby).
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
# NOTE: whitespaces between the number and the "," in the parentheses are optional. | |
RGB = /^rgb\((\d{1,2}|([01][0-9][0-9]|((25[0-5])|2[0-4]\d))),(| )(\d{1,2}|([01][0-9][0-9]|((25[0-5])|2[0-4]\d))),(| )(\d{1,2}|([01][0-9][0-9]|((25[0-5])|2[0-4]\d)))\)$/i | |
RGBA = /^rgba\((\d{1,2}|([01][0-9][0-9]|((25[0-5])|2[0-4]\d))),(| )(\d{1,2}|([01][0-9][0-9]|((25[0-5])|2[0-4]\d))),(| )(\d{1,2}|([01][0-9][0-9]|((25[0-5])|2[0-4]\d)))(,|, )(0|1|0.\d|1.0)\)$/i | |
HEXA = /^#(\d|[a-f])(\d|[a-f])(\d|[a-f])(|(\d|[a-f]))$/i | |
HEX = /^#(\d|[a-f])(\d|[a-f])(\d|[a-f])$/i | |
HHEEXX = /^#(\d\d|\d[a-f]|[a-f]\d|[a-f][a-f])(\d\d|\d[a-f]|[a-f]\d|[a-f][a-f])(\d\d|\d[a-f]|[a-f]\d|[a-f][a-f])$/i | |
HHEEXXAA = /^#(\d\d|\d[a-f]|[a-f]\d|[a-f][a-f])(\d\d|\d[a-f]|[a-f]\d|[a-f][a-f])(\d\d|\d[a-f]|[a-f]\d|[a-f][a-f])(|(\d\d|\d[a-f]|[a-f]\d|[a-f][a-f]))$/i | |
HSL = /^hsl\((\d|\d\d|[1-2]\d{2}|(3([0-5]\d|60))),(| )(\d|\d\d|100)%,(| )(\d|\d\|100)%\)$/i | |
HSLA = /^hsla\((\d|\d\d|[1-2]\d{2}|(3([0-5]\d|60))),(| )(\d|\d\d|100)%,(| )(\d|\d\|100)%(,|, )(1.0|0|1,0.\d)\)$/i |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment