Which Google Spreadsheets formula do I use to get the domain part from an email address?
Example: [email protected]
→ example.com
Web Applications Stack Exchange is a question and answer site for power users of web applications. It only takes a minute to sign up.
Sign up to join this communityWhich Google Spreadsheets formula do I use to get the domain part from an email address?
Example: [email protected]
→ example.com
I would use the following formula to obtain an URL.
=IF(ISEMAIL(A2),
REGEXEXTRACT(A2,"@(.+)"),
IF(ISURL(A2),
A2,
IF(ISURL(REGEXEXTRACT(A2,"@(.+)")),
REGEXEXTRACT(A2,"@(.+)"),
"No valid entry"
)
)
)
Copy / Paste
=IF(ISEMAIL(A2),REGEXEXTRACT(A2,"@(.+)"),IF(ISURL(A2),A2,IF(ISURL(REGEXEXTRACT(A2,"@(.+)")),REGEXEXTRACT(A2,"@(.+)"),"No valid entry")))
A1
is validated for being an e-mail address. If TRUE
, then use the REGEXEXTRACT
formula you constructed. If the e-mail address turns out to be not a valid address, then validate for an URL. If the URL turns out to be not a valid URL, then check if the REGEX
is an valid URL. Show text No valid entry is no of the IF
statements are true.
I've created an example file for you: Get domain from email address
=split(A2, "@")
in A3 would put bob
in A3 and example.com
in A4. A little more concise.
Oct 21, 2014 at 16:48
This formula will do the job:
=REGEXEXTRACT(A1, "@(.*)")
If no @
is found, the original value is shown.
The =regexextract
function (documentation) executes the regular expression parameter (@(.*)
) against the value of cell A1
, and returns the matching group.
(.*)
is too generic. Btw, if no match is found, it will throw an error.
Oct 21, 2014 at 10:38
"@([A-Za-z0-9-.]+)")
Oct 21, 2014 at 11:45
If your email address ([email protected]) is in A1
=index(split(A1,"@"),0,2)
= example.com
=index(split(A1,"@"),0,1)
= bob
You are splitting on the @ and than using index to select which column you want from the split.