user4227915
user4227915

Reputation:

Match all gray-scale colors in hex

Suppose I have a file with some hex colors:

.. #101010   ..   match
.. #a2a2a2   ..   match
.. #abcd10   ..   do not match
.. #000000   ..   match
.. #111222   ..   do not match
.. #ffffff   ..   match
.. #3b3b3b   ..   match
.. #121012   ..   do not match
.. #fff      ..   match
.. #aba      ..   do not match

How to select all hex-colors which red, green and blue values are the same?

Thanks in advance.

Upvotes: 1

Views: 164

Answers (2)

Steven Ding
Steven Ding

Reputation: 74

Just tried this works in vim:

([0-9a-f][0-9a-f])\1\1

Upvotes: 1

anubhava
anubhava

Reputation: 785761

You can use this regex:

#([a-fA-F\d]{1,2})\1{2}\b

RegEx Demo

\1 is back-reference of first 1 or 2 digits after #

RegEx Breakup:

#                  # Match a literal hash or #
([a-fA-F\d]{1,2})  # Match 1 or 2 hex digit and group it as captured group #1
\1{2}              # Match 2 more occurrences of back-reference \1
\b                 # Assert a word boundary

Upvotes: 5

Related Questions