Created
June 11, 2014 08:49
-
-
Save ssaunier/3187042b05f8882f0947 to your computer and use it in GitHub Desktop.
Email parser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
EMAIL_PATTERN = /([^\.@]+)(\.([^@]+))?@([^@]+)/ | |
def parse_email(email) | |
groups = EMAIL_PATTERN.match(email) | |
if groups.nil? | |
raise ArgumentError.new("'#{email}' is not a valid email address") | |
else | |
firstname = groups[1] | |
lastname = groups[3] | |
email_domain = groups[4] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment