-
Notifications
You must be signed in to change notification settings - Fork 3
/
findEmailDomain.R
executable file
·26 lines (24 loc) · 1.06 KB
/
findEmailDomain.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# An email address such as "[email protected]" 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 = "[email protected]", the output should be
# findEmailDomain(address) = "example.com"; For address =
# "[email protected]", the output should be
# findEmailDomain(address) = "codesignal.com".
# address = "\"[email protected]\"@usual.com"
findEmailDomain <- function(address) {
getlocnofattherate <- gregexpr("@",address)
#if more than 1 @ take the last one
numberofinstances = length(getlocnofattherate[[1]])
relevantstartindex = getlocnofattherate[[1]][numberofinstances]
return(substr(address,(relevantstartindex + 1),nchar(address)))
}