I stumbled across (?<=\@)(.*?)(?=\.)
here on StackOverflow, but apparently possitive lookbehinds are not supported in JavaScript.
I modified it a little to use /(@)(.*?)(?=\.)/
and I can obtain the last part of an email.
My problem is now trying to extract the last part if there are two .
characters.
For example:
const[x, y, lastPart]="foo@bar.com".match(/(@)(.*?)(?=\.)/) //lastPart = bar
const[x, y, lastPart]="foo@mailinator.com".match(/(@)(.*?)(?=\.)/) //lastPart = mailinator
These cases work perfectly, but when I try with foo@my.domain.com
, I would like to extract my.domain
and not my
.