Find Email Domain
An email address such as "John.Smith@example.com"
is made up of a local part ("John.Smith"
), an "@"
symbol, then a domain part ("example.com"
).
The domain name part of an email address may only consist of letters, digits, hyphens and dots. The local part, however, also allows a lot of different special characters. Here you can look at several examples of correct and incorrect email addresses.
Given a valid email address, find its domain part.
Example
For
address = "prettyandsimple@example.com"
, the output should befind_email_domain(address) = "example.com"
For
address = "fully-qualified-domain@codesignal.com"
, the output should befind_email_domain(address) = "codesignal.com"
Solution
py
def find_email_domain(address):
return address[address.rindex('@') + 1:]
print(find_email_domain('abc@gmail.com'))
js
function find_email_domain(address) {
return address.split('@').pop();
}
console.log(find_email_domain('abc@gmail.com'));