How do I get the domain from an email-adress in ruby?
Use the ICANN Lookup tool to find your domain host. Go to lookup.icann.org. In the search field, enter your domain name and click Lookup. In the results page, scroll down to Registrar Information.
A domain name (often simply called a domain) is an easy-to-remember name that's associated with a physical IP address on the Internet. It's the unique name that appears after the @ sign in email addresses, and after www. in web addresses.
To extract domain from email address Select a blank cell to place this formula =RIGHT(A2,LEN(A2)-FIND("@",A2)), press Enter key, and drag fill handle down to the cells which need this formula.
>> "[email protected]".split("@").last
=> "mycorp.com"
If you prefer using a library dedicated to understanding these things:
→ irb -rmail
ruby-1.9.2-p0 > Mail::Address.new('[email protected]').domain
=> "example.com"
>> email = "Sahil Grover<[email protected]>"
=> "Sahil Grover<[email protected]>"
>> mail = Mail::Address.new(email)
=> #<Mail::Address:75152940 Address: |Sahil Grover <[email protected]>| >
>> mail.instance_values
=> {"output_type"=>:decode,
"parsed"=>true,
"data"=>#<struct Mail::Parsers::AddressStruct
raw="Sahil Grover<[email protected]>",
domain="stackoverflow.com",
comments=[],
local="sahil+test",
obs_domain_list=nil,
display_name="Sahil Grover",
group=nil,
error=nil>,
"display_name"=>"Sahil Grover"}
>> mail.domain
=> "stackoverflow.com"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With