admin管理员组文章数量:1360339
I'm working with a PostgreSQL database where email addresses are stored in a string along with names, like this:
Lucky kurniawan <[email protected]>
I need to extract only the domain (e.g., hotmail).
I'm working with a PostgreSQL database where email addresses are stored in a string along with names, like this:
Lucky kurniawan <[email protected]>
I need to extract only the domain (e.g., hotmail).
Share Improve this question asked Apr 1 at 10:12 lucky kurniawanlucky kurniawan 1362 silver badges8 bronze badges 1 |2 Answers
Reset to default 0I attempted to use substring()
with regex but haven't found the best approach.
Here’s an SQL query that partially works:
SELECT substring(email_from FROM '<[^@]+@([^>]+)>') AS domain
FROM my_table;
For the input Lucky kurniawan <[email protected]>
, it correctly returns:
hotmail
SELECT
substring(email_from FROM '.*<([^@]+@[^>]+)>') AS domain
FROM
my_table;
It will match any character before the "<" making it more flexible.
It also captures the full email address inside the < > and then then extracts the domain.
本文标签: regexHow to extract the domain from an email in a string using PostgreSQLStack Overflow
版权声明:本文标题:regex - How to extract the domain from an email in a string using PostgreSQL? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743894533a2557536.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
select split_part('[email protected]', '@', 2);
– Mike Organek Commented Apr 1 at 12:09