Today it is your lucky day!!! I will bless you with the knowledge of the "Matching A Hex Value " Regular Expression! So have a seat get comfy and read on, be amazed at this knowledge bomb.
This regex /^#?([a-f0-9]{6}|[a-f0-9]{3})$/) will match a hex value in this tutorial we are going to break it down!
There are two anchors in this expression ^ which means "beginning " and $ which means "end"
There are actually three "quantifiers in this regular expression! The first being ? which " Matches between 0 and 1 of the preceeding token"! Another quantifier the second in line is {6} this quantifier matches 6 of the preceeding token's the final quantifier in this regex is {3} which as you guessed probably will "match three of the preceeding token's!!!
this little symbol | found in this regex"act's like a boolean OR. it Matches the expression before or after the |.!!! Sounds fantastic Right!?
So there is some capturing going on here! () these surounding "[a-f0-9]{6}|[a-f0-9]{3}"capturing two groups [a-f0-9] of character sets!!
There are two character sets in this regex both being identical to one another [a-f0-9]. Lets break this down so a-f Matches a character in the range of a to f which would be (Charcode 97 to 102). this is also Case Sensitive! The character set 0-9 "Matches a character in the range of 0 to 9 !!! which would be (Charcode 48 to 57)! Which is also case sensitive.
the # symbol in this case matches a "#" it has a (Charcode of 35) How neat!!!
Sebastian Bowen A cool and unique guy you either like him or not...https://github.com/Sebastian2908-2007