import pycountry import re def extract_country_name(string): pattern = r"\b[A-Za-z ]+\b" # Matches any sequence of letters and spaces matches = re.findall(pattern, string) for match in matches: try: country = pycountry.countries.lookup(match) print("COUNTRY : ",country.name) return True, country.name except LookupError: pass return False, None