PostgreSQLdata extraction

Extract Email Domain in PostgreSQL with regexp_replace

Use PostgreSQL regexp_replace to extract the domain part from email address columns. SQL examples for email domain analysis.

The Regex Pattern

Regex pattern

^[^@]+@(.+)$

Use this pattern with PostgreSQL's ~ operator.

PostgreSQL SQL Example

-- Extract domains from email addresses in a PostgreSQL users table for analytics using regexp_replace
SELECT *
FROM your_table
WHERE your_column ~ '^[^@]+@(.+)$';

How This Works

Extract domains from email addresses in a PostgreSQL users table for analytics using regexp_replace. The regex pattern is used with PostgreSQL's ~ operator to filter rows at the database level.

Using regex directly in SQL is efficient for use cases like data extraction โ€” it avoids loading data into application memory just to filter it with a regex.

Need a custom SQL + Regex query?

Describe your specific use case in plain English. RegSQL generates the exact PostgreSQL query with the right regex pattern for your schema.

Related SQL Patterns