Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

217
Views
JS regex to get domain name from an email

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:

  1. I don't want to keep subdomains. (ex: hello@sub.domain.com should return domain.com )
  2. Some domain extensions have two dots. (ex: hello@domain.co.uk should return domain.co.uk)
  3. It is possible to include an at (@) 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
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!