简体   繁体   中英

how to extract this pattern with SQL BIGQUERY?

From this clause: b-12345_xx_aa_bbb_xsx-latam_jan_11_a12

I want to extract with REGEXP_EXTRACT:

  • b-12345
  • xx
  • aa
  • bbb

Thanks in advance

Try below

select col,
  parts[offset(0)], 
  parts[safe_offset(1)], 
  parts[safe_offset(2)], 
  parts[safe_offset(3)]
from your_table, unnest([struct(split(col, '_') as parts)]) 

if applied to dummy data in your question - output is

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM