Alex
Alex

Reputation: 1537

Regular Expression bigquery

How do I extract from an email string only the following part:

[email protected]
[email protected]

Desired result:

ux.ca
ca

Basically, everything that comes later than @ AND the first 'dot'

Upvotes: 0

Views: 46

Answers (1)

Mikhail Berlyant
Mikhail Berlyant

Reputation: 172993

everything that comes later than @ AND the first 'dot'

You can use REGEXP_EXTRACT(email, r'@[^.]+.(.*)')

for example

#standardSQL
WITH `project.dataset.table` AS (
  SELECT '[email protected]' email UNION ALL
  SELECT '[email protected]'
)
SELECT 
  email, 
  REGEXP_EXTRACT(email, r'@[^.]+.(.*)')
FROM `project.dataset.table`

with result

Row email                   f0_  
1   [email protected] ux.ca    
2   [email protected]     ca   

Upvotes: 2

Related Questions