Library

DFA · Regular

A hex colour: #rgb or #rrggbb

A # and exactly three or six hex digits (h). After three digits the machine is in an accepting state that can still be extended — but only by exactly three more.

sh0h1h2h3h4h5h6#hhhhhh
The machine as drawn — 8 states, 7 transitions.

The author’s examples, run

#hhh → accept#hhhhhh → accepthhhh → rejecthhhhhhh → rejectε → reject##hh# → reject