Code:
var COLOR_PATTERN = /#[0-9a-z]{3,6}|rgb\(\s*(?:[\d]{1,3})(?:%)?\s*\,\s*(?:[\d]{1,3})(?:%)?\s*\,\s*(?:[\d]{1,3})(?:%)?\s*\)/i;
(IE doesn't support const kwd and I'm tryina support IE).
Here's a breakdown:
Code:
#[0-9a-f]{3,6} - matches #333 or #ff0044
rgb\( - matches rgb(
\s*(?:[\d]{1,3})(?:%)?\s* - matches 122 or 122% -- call this nPattern.
\, - matches a comma
\s*(?:[\d]{1,3})(?:%)?\s*\ -(SAME AS nPattern)
\, - matches a comma
\s*(?:[\d]{1,3})(?:%)?\s* - (SAME AS nPattern)
\)/i;
My question is regarding the simplification of nPattern. I repeat the same thing three times. Can I store and backreference within the same pattern? I don't know if it's possible.