The second Regex Tuesday challenge is slightly trickier challenge. Unlike the last challenge, it is to match something, not to replace something.

In this challenge, you are aiming to match a grayscale CSS colour. It should be able to match anything but the colour names (eg "red"). See the test cases below for examples.

To test a regular expression on the test cases below, type it into the text input. Each test case will be marked as passed or failed respectively - you are aiming to get as many test cases as you can to pass. Note that JavaScript must be enabled for this feature to work. The regex engine used is the JavaScript regex engine; it is similar to PCRE, but with a few differences.

If you're finding this challenge too tricky, you can simplify it - for example, to match all the hex colours (eg " #000 "), and then move onto the rgb colours. hsl can be a bit trickier - do as much or as little as you can. For an explanation of the various colour syntaxes available, check out this article. Good luck!

Test cases ( 0 /40) Permalink Hide passing tests

#000 match #aaa match #eEe match #111111 match #6F6F6F match #efEfEF match rgb(0, 0, 0) match rgb(15,15,15) match rgb(2.5, 2.5,2.5) match rgb(1, 01, 000001) match rgb(20%, 20%,20%) match rgba(4,4,4,0.8) match rgba(4,4, 4,1 ) match rgba(3,3,3,0.12536) match rgba(10%,10%,10%,5%) match hsl(20,0%, 50%) match hsl(0, 10%, 100%) match hsl(0.5, 10.5%, 0%) match hsl(5, 5%, 0%) match hsla(20, 0%, 50%, 0.88) match hsla(0, 0%, 0%, 0.25) match #ef4 no match #eEf no match #11111e no match #123456 no match rgb(2, 4, 7) no match rgb(10, 10,100) no match rgb(1.5%, 1.5%, 1.6%) no match rgba(1, 01, 0010, 0.5) no match hsl(20, 20%, 20%) no match hsl(0, 1%, 01%) no match hsla(0, 10%, 50%, 0.5) no match #11111 no match #000000000 no match rgb (1, 1, 1) no match rgb(10, 10, 10, 10) no match rgb(257, 257, 257) no match rgb(10%, 10, 10) no match hsl (20,0%, 50%) no match argb(1,1,1) no match

Congratulations, your regex passes all the test cases! Remember to share this challenge.