user1609817 user1609817 - 1 year ago 70
SQL Question

Remove part of an email address

I have emails like

sales@joebloggs.com
.

I am looking to select out everything after the
@
and before the
.
.

Result should be
joebloggs
.

Answer Source

Simple regex pattern should do the job.

SELECT regexp_matches('sales@joebloggs.subdomain.com', '@([^.]+)\.');

SQL Fiddle

Edit: fixed to support subdomains. I assume you want to get the part before first dot.