File size: 429 Bytes
7bbae49
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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