# re date validate/extract particular dd/mm/yyyy s= 24-12-2021 l = re.compile("^(?P<date>[0-9]{2})-(?P<month>[0-9]{2})-(?P<year>[0-9]{4})$") m = re.search(r,s) if m: print(m.group("year")) else: print("pattern not found")