I am trying to return the date from a longer string. The date could be any weekday, any number with a subscript st, nd, rd, th
and the month as 3 string values (Jan, Feb etc)
.
This is my attempt but I'm getting None. Not sure what I'm missing?
string = 'Times for Saturday 10th Aug'
days = ('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday')
months = ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec')
pat = re.compile(r'^(%s) (\d+)(st|nd|rd|th) (%s)$' %
('|'.join(days), '|'.join(months)))
print(re.match(pat, string))