Posted By

Corhol on 11/20/06


regexp hexadecimal

Versions (?)

Who likes this?

4 people have marked this snippet as a favorite


Hexadecimal Value

 / Published in: Regular Expression

Matches any hex value (0123456789ABCDEF) preceded by the pound sign (#) of exactly 3 or 6 digits in length.

  1. /(#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})\b)/

Report this snippet  


RSS Icon Subscribe to comments
Posted By: priyanhere on November 21, 2006

This is good, but below is more efficient /(#([0-9A-Fa-f]{3,6})\b)/

Posted By: CUViper on November 23, 2006

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:


You need to login to post a comment.