im trying to do this (Write a regular expression that can detect dates in the DD/MM/YYYY format. Assume that the days range from 01 to 31, the months range from 01 to 12, and the years range from 1000 to 2999. Note that if the day or month is a single digit, it’ll have a leading zero. The regular expression doesn’t have to detect correct days for each month or for leap years; it will accept nonexistent dates like 31/02/2020 or 31/04/2021.)
the solution is giving me 4 values in a tuple (date, day, month, year) instead of just (date) how do i fix this? thanks in advance.
import re
dates_regex = re.compile(r'''(
#day
(0[1-9]|[12][0-9]|3[01])
/
(0[1-9]|[10][12])
/
([1-2][0-9][0-9][0-9])
)''', re.VERBOSE)
string = """ 05/06/400
06/05/2031
29/04/5000
08/07/2164
01/12/1832
27/09/6000
08/01/1810
16/05/1503
35/12/2000
21/09/1915"""
regex_search = dates_regex.findall(string)
print(regex_search)
running the code results in:
[('06/05/2031', '06', '05', '2031'), ('08/07/2164', '08', '07', '2164'), ('01/12/1832', '01', '12', '1832'), ('08/01/1810', '08', '01', '1810'), ('16/05/1503', '16', '05', '1503'), ('21/09/1915', '21', '09', '1915')]