Skip to content

Instantly share code, notes, and snippets.

@vmcilwain
Last active February 5, 2019 15:23
Show Gist options
  • Select an option

  • Save vmcilwain/6918762cf40d28f428ff4b23affd4e78 to your computer and use it in GitHub Desktop.

Select an option

Save vmcilwain/6918762cf40d28f428ff4b23affd4e78 to your computer and use it in GitHub Desktop.
[Ruby] Email address scanner and verify
# scan for email addresses
text-variable.scan(/\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b/i)
=> ['user1@domain.com', 'user2@domain']
# Verify email addresses
a = Mail::Address.new('Foo Bar <foobar@example.com>')
a.address
=> "foobar@example.com"
# or
a = Mail::Address.new('foobar@example.com')
a.address
=> "foobar@example.com"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment