Regex get domain name from email

[^@] means “match one symbol that is not an @ sign. That is not what you are looking for – use lookbehind (?<=@) for @ and your (?=\.) lookahead for \. to extract server name in the middle:

(?<=@)[^.]+(?=\.)

The middle portion [^.]+ means “one or more non-dot characters”.

Demo.

Leave a Comment