# Get digit using regex import re def extract_num_from_string(string: str) -> int: return ''.join(re.findall('d', string)) print(extract_num_from_string('Year 2000')) # output will be: 2000