I am trying to find the perfect regex that will help me extract the domain name of an email. (ex: hello@domain.com should return domain.com)
A lot of issue on SO address this problem but none of them treat it perfectly.
Here are the special edge cases that I want to tackle:
hello@sub.domain.com should return domain.com )hello@domain.co.uk should return domain.co.uk)@) in your domain name (although most registrar do not allow it). (ex: hello@dom@in.com should return dom@in.com)I have tried the following regex but they don't tackle all the edge cases:
/(?<=@)\S+\.\S+$/ => Does not handle case 1/[^.@]*?\.\w{2,}$|[^.@]*?\.com?\.\w{2}$/ => Does not handle case 3