Q:

Given an input with a period, how to get everything trailing it?

Given inputs like the following
bob - invalid
bob. - invalid
bob.edu - valid
bob.com - valid
bob.newco.com - valid

In Ruby, I'd like a way to first determine if there is a period, if there is I want everything after the last period?
I tried doing 
domain_ext = search_input.split('.').last

Problem is, if the input is roger. that is returning 5, thinking roger is the ext. I don't know how to tell Ruby only after the last period?

A:

The same regex can be used to filter out domains with a TLD, and return the TLD:
/\.(.+?)$/

Here are some use examples:
domains = %w[ foo foo. foo.com ].select{ |d| d[/\.(.+?)$/, 1] }
=> ["foo.com"]
domains = %w[ foo foo. foo.com ].map{ |d| d[/\.(.+?)$/, 1] }
=> [nil, nil, "com"]

Based on Sawa's comment:
%w[ foo foo. foo.com foo.bar.com ].select{ |d| d[/(?<=\.)([a-z0-9-]+?)$/i, 1] }
=> ["foo.com", "foo.bar.com"]

%w[ foo foo. foo.com foo.bar.com ].map{ |d| d[/(?<=\.)([a-z0-9-]+?)$/i, 1] }
=> [nil, nil, "com", "com"]

