Stack Exchange
regex date DD/MM/YYYY
Can someone please explain how all components of this regex work?
const carDateRegex = /^([0-2][0-9]|(3)[0-1])(\/)(((0)[0-9])|((1)[0-2]))(\/)\d{4}$/

Will find dates with format: DD/MM/YYYY (for example: 31/12/2019)

Ref: Regex101.com
^([0-2][0-9]|(3)[0-1])(/)(((0)[0-9])|((1)[0-2]))(/)\d{4}$
/
^ asserts position at start of the string
1st Capturing Group ([0-2][0-9]|(3)[0-1])
1st Alternative [0-2][0-9]
Match a single character present in the list below [0-2]
0-2 a single character in the range between 0 (index 48) and 2 (index 50) (case sensitive)
Match a single character present in the list below [0-9]
0-9 a single character in the range between 0 (index 48) and 9 (index 57) (case sensitive)
2nd Alternative (3)[0-1]
2nd Capturing Group (3)
3 matches the character 3 literally (case sensitive)
Match a single character present in the list below [0-1]
0-1 a single character in the range between 0 (index 48) and 1 (index 49) (case sensitive)
3rd Capturing Group (\/)
\/ matches the character / literally (case sensitive)
4th Capturing Group (((0)[0-9])|((1)[0-2]))
1st Alternative ((0)[0-9])
5th Capturing Group ((0)[0-9])
6th Capturing Group (0)
0 matches the character 0 literally (case sensitive)
Match a single character present in the list below [0-9]
0-9 a single character in the range between 0 (index 48) and 9 (index 57) (case sensitive)
2nd Alternative ((1)[0-2])
7th Capturing Group ((1)[0-2])
8th Capturing Group (1)
1 matches the character 1 literally (case sensitive)
Match a single character present in the list below [0-2]
9th Capturing Group (\/)
\/ matches the character / literally (case sensitive)
\d{4} matches a digit (equal to [0-9])
{4} Quantifier — Matches exactly 4 times
$ asserts position at the end of the string, or before the line terminator right at the end of the string (if any)

