Find Email Domain

Description


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 be findEmailDomain(address) = "example.com";
  • For address = "<>[]:,;@\"!#$%&*+-/=?^_{}| ~.a\"@example.org", the output should be findEmailDomain(address) = "example.org".

Input/Output

  • [execution time limit] 4 seconds (js)

  • [input] string address

Guaranteed constraints: 10 ≤ address.length ≤ 50.

  • [output] string

[JavaScript (ES6)] Syntax Tips

1
2
3
4
5
6
// Prints help message to the console
// Returns a string
function helloWorld(name) {
    console.log("This prints to the console when you Run Tests");
    return "Hello, " + name;
}

Solution


1
2
3
function findEmailDomain(address) {
    return /^.*@([.\w\d]+)$/.exec(address)[1];
}