'/' = denotes the start and stop of a regex. /[ABC]/ (look for A, B or C)
'?' = Match the expression 0 or 1 times /[ABC]?/ (Look for A, B or C zero or one time)
'' = Match the expressions 0 or more times /[ABC]/ look for A, B or C zero or one times.
'+' = Match the expression 1 or more times /[ABC]+/ look for A, B or C at least once.
'.' = matches any character
{6} = Match the number of characters inside the {} (in this case, match 6 characters.
'^' = anchor the regex to the beginning of a string
'' Anchors (start and stop)
(..|..) Grouping (this or that).
/i = ignore case.
'\d' = matches any decimal digit; for example, 5. A variance of this is '\D' that matches any non-digit character.
'\s': matches any whitespace character; for example, ''. A variance of this is '\S' that matches any non-whitespace character.
'\w': matches any alphanumeric character; for example, 'Pluralsight'. A variance of this is '\W' that matches any non-alphanumeric character.
‘a-z’: matches lowercase groups.
‘A-Za-z’: matches upper and lowercase English alphabet.
‘0-9’: matches numbers from 0 to 9.
search for a valid color scheme: #00002C.
(Correct format is #, then 3 set of 2 characters, A-F, and 0-9)
/#[ABCDEF0123456789]+/
or /#[A-F0-9]+/
/#?[A-F0-9]{6}/
= Will match #AA0011 or AA0011, but won't match #AA1 or AA1
the #? says to look for the # 0 or 1 times. This will look for exactly 6 characters {x}.
match namespaces 106144d106145-myapp1-prod1-prod, 106144d106145-myapp2-prod2-prod, 106144d106145-myapp1-prod2-prod, 106144d106145-myapp3-prod1-prod
/[1][0][6][1][4][4].*prod/
/#?([A-F0-6]{6}|[A-F0-6]{3})/
This will look for anything starting with a "#" with either 3 or 6 characters after the "#" with letters between A-F or numbers between 0-6.
(19|20)\d\d([- /.])(0[1-9]|1[012])\2(0[1-9]|[12][0-9]|3[01])
Date | 0 | 1 | 2 | 3 | 4 |
---|---|---|---|---|---|
1900-01-01 | 1900-01-01 | 19 | - | 01 | 01 |
2007/08/13 | 2007/08/13 | 20 | / | 08 | 13 |
1900.01.01 | 1900.01.01 | 19 | . | 01 | 01 |
1900 02 31 | 1900 02 31 | 19 | 02 | 31 |
The expression ^#([0-6A-Fa-f]{6}$
will match
#A304FC
because it's matching the expression against the entire line, start (^) to stop ($)
but will not match
This is a color #A304FC
because the valid color code doesn't start at the beginning of the line.
regexper.com is great for visualizing regular expressions.