import re s = '2020-10-9' mat = re.search(r"(\d{4}-\d{1,2}-\d{1,2})",s) print(mat)