Python - Extract domain name from Email address Last Updated : 18 Jan, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report Extracting the domain name from an email address involves isolating the part after the @ symbol. For example we are having string email= "[email protected]" so we need to extract the domain name of email address so that the output becomes "example.com". To do this operation we can use methods like spilt(), partition(), Regular expression.Using split()split() method in Python divides a string into a list of substrings based on a specified delimiter. Python email = "[email protected]" # Splitting the email string at the '@' symbol and accessing the second part (domain) domain = email.split('@')[1] print(domain) Outputexample.com Explanation:split('@') function splits the string at the @ symbol.Second part of the split string ([1]) is the domain nameUsing Regular Expressions (re.search)re.search() method in Python searches for a pattern within a string and returns the first match found. Python import re # Defining an email string e = "[email protected]" # Using the search function to find a match for the domain part of the email match = re.search(r'@([a-zA-Z0-9.-]+)', e) # If a match is found, extracting the domain part (the part after '@') using the group() method if match: domain = match.group(1) print(domain) Outputexample.com Explanation:Regular expression @([a-zA-Z0-9.-]+) matches the domain part after the @ symbol.match.group(1) retrieves the matched domain.Using partition()partition() method splits the string into three parts: before the '@', the '@' symbol, and after the '@'. domain part is extracted by accessing third element using index. Python email = "[email protected]" # Splitting the email at '@' and selecting the domain part domain = email.partition('@')[2] print(domain) Outputexample.com Explanation:partition('@') method splits the string into three parts: the part before the @, the @, and the part after.Domain is the third part, accessed with [2]. Comment More infoAdvertise with us Next Article Python | Extract words from given string M manjeet_04 Follow Improve Article Tags : Python Python Programs Python string-programs Practice Tags : python Similar Reads Check if email address valid or not in Python Given a string, write a Python program to check if the string is a valid email address or not. An email is a string (a subset of ASCII characters) separated into two parts by the @ symbol, a "personal_info" and a domain, that is [email protected]: Email Address Validator using re.match()P 3 min read Python program to validate an IP Address Prerequisite: Python Regex Given an IP address as input, write a Python program to check whether the given IP Address is Valid or not. What is an IP (Internet Protocol) Address? Every computer connected to the Internet is identified by a unique four-part string, known as its Internet Protocol (IP) a 4 min read Finding IP Address using Python An IP(Internet Protocol) address is an identifier assigned to each computer and other device(e.g., router, mobile, etc.) connected to a TCP/IP network that is used to locate and identify the node in communication with other nodes on the network. IP addresses are usually written and displayed in huma 2 min read Python | Extract words from given string In Python, we sometimes come through situations where we require to get all the words present in the string, this can be a tedious task done using the native method. Hence having shorthand to perform this task is always useful. Additionally, this article also includes the cases in which punctuation 4 min read Python program to find the type of IP Address using Regex Prerequisite: Python Regex Given an IP address as input, write a Python program to find the type of IP address i.e. either IPv4 or IPv6. If the given is neither of them then print neither. What is an IP (Internet Protocol) Address?Every computer connected to the Internet is identified by a unique fo 2 min read Extract Data From JustDial using Selenium Let us see how to extract data from Justdial using Selenium and Python. Justdial is a company that provides local search for different services in India over the phone, website and mobile apps. In this article we will be extracting the following data: Phone numberNameAddress We can then save the dat 2 min read Like