The purpose of this tutorial is to show you how to use regular expression. Learning this can help locate snipets of code with almost all programming languages. You can use these to find certain combinations within a string. I will be using this gist to identify some of these expressions.
/^#?([a-f0-9]{6}|[a-f0-9]{3})$/
This regular expression is used to match Hex Values. All of this will be broken down, and I will be explaining how these are used in this particular Regex. You can use this site to help further your understanding of Regex https://regexr.com/
^ - Used at the beginning $ - Used at the end
We use anchors to see if the matching symbol is at the start or end. The don't really match a character they just help identify the position before or after a character.
? - Matches 0 or 1 of the preceding token {6} - Match 6 of the preceding token {3} - Match 6 of the preceding token
Qualifiers in this example tell you how many letters or numbers to match to the token in front of it. The ? is saying to match with # atleast 0 or 1 time, making this an optional requirement. The number in {} is lettin gus know that we need to match a-z0-9 by 6 or 3 characters.
| - Acts like a boolean OR. Matches the expression before or after the |
This just means OR. In this regex it would mean find a match with 6 letter and numbers 'OR' find a match with 3 letters and numbers. This can operate with a group or whole expression.
# - Matches a "#" character [a-f0-9] - Match any character in this set
Character Classes will look up letters a through f, and numbers 0 through 9. This will also include those letters used to create the range. The # used here is telling the expression to find that symbol before the group we call.
GitHub: https://github.com/jessangarcia