I've an XML file containing (among a lot of other stuff) hexadecimal color codes. I want to inspect all such codes that result in shades of grey. The pattern is
- a hash tag (#) then
- [a-fA-F0-9] repeated exactly 3 or 6 times
- [^a-fA-F0-9]
So it should match #eee, #EEEEEE, #333333 but not #00006d, #123456 and so on. Regarding the regex flavor, it should ideally work in Notepad++, if that's no option then Python 2.7 is an alternative.
I tried using the backreference operator I found here. So far, my best attempt is
#([0-9a-fA-F])\1{3}[^0-9a-fA-F]
but I'm having some troubles:
- It seems I should replace
{3}
by{2}
for matching exactly three repetitions but I don't see why - I'm clueless as to how to match 6 repetitions as well. I think that
{3,6}
should match 3, 4, 5 or 6 repetitions but how can I exclude 4 and 5 repetitions? I thought about#([0-9a-fA-F])\1{3}[^0-9a-fA-F]|#([0-9a-fA-F])\1{6}[^0-9a-fA-F]
but there must be a less ugly syntax for that, right?