import re device_type = "AXO145" stats_access_link = "https://xcd32112.smart_meter.com" pattern = r'https:\/\/([a-zA-Z0-9_\.]+)<\/url>' match = re.search(pattern, stats_access_link) if match: domain = match.group(1) print(domain)