Published in: Regular Expression
Matches any hex value (0123456789ABCDEF) preceded by the pound sign (#) of exactly 3 or 6 digits in length.
/(#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})\b)/
Comments
Subscribe to comments
You need to login to post a comment.

I don't think that's the same thing, priyanhere. From the perlre manpage:
{n,m} Match at least n but not more than m times
Thus your example would also match 4 or 5 digits. Since we're looking for exactly 3 or 6, and those happen to be multiples, you could try this:
This is good, but below is more efficient /(#([0-9A-Fa-f]{3,6})\b)/