Skip to content

Instantly share code, notes, and snippets.

@ssaunier
Created June 11, 2014 08:49
Show Gist options
  • Save ssaunier/3187042b05f8882f0947 to your computer and use it in GitHub Desktop.
Save ssaunier/3187042b05f8882f0947 to your computer and use it in GitHub Desktop.
Email parser
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