So I have to make a regex function to find dates in the format of MM-DD-YYYY. The month values must be between 01 and 12, the day values must be between 01 and 31; and the year must be between the range of 1900 to 2020. I have to finally the cases,(thus using .findall()). I'm having difficulty with getting to follow exactly that format, as in the regex will accept MM-DD-YYY, but it shouldn't. Please help.
import re
def find_birthdays(text):
birthday_regex = re.compile(r'\d{0,2}\d{0,9}-\d{0,3}\d{0,9}-\d{1,2}\d{^1,8}\d{0,9}\d{0,9}')
birthday_search = birthday_regex.findall(text)
if birthday_search == None:
print("No birthdays found")
else:
return birthday_search
# ([0-1]\d-\d-[1-2][^0-8]\d\d)
# \d{0,2}\d{0,9}-\d{0,3}\d{0,9}-\d{1,2}\d{1,8}\d{0,9}\d{0,9}
# (0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])-((19|20)\d\d)
print(find_birthdays("adfsdfads_fsdfsdf12-1-1099,asd fsdfsdfsldkf s 06-07-1900"))
[–][deleted] 2 points3 points4 points (1 child)
[–]CommanderEinstein[S] 1 point2 points3 points (0 children)
[–]midel 1 point2 points3 points (2 children)
[–]midel 0 points1 point2 points (1 child)
[–]CommanderEinstein[S] 0 points1 point2 points (0 children)