正则表达式解决以下问题

时间:2017-05-15 19:06:36

标签: regex google-bigquery

示例1

asdk[wovkd'vk'psacx U5 = 205478499 | 205477661 zamd;amd;a;d

示例2

sadlmdlmdadsld U5 = 205478499 | 205477661 | 234567899 amsd/samdamd

u5可以将多个值分隔为|

如何从我拥有的长字符串中捕获所有u5值?

1 个答案:

答案 0 :(得分:2)

以下是BigQuery Standard SQL

#standardSQL
WITH data AS (
  SELECT 1 AS id, "asdk[wovkd'vk'psacxu5=205478499|205477661zamd;amd;a;d" AS junk UNION ALL
  SELECT 2, "sadlmdlmdadsldu5=205478499|205477661|234567899amsd/samdamd"
)
SELECT id, SPLIT(REGEXP_EXTRACT(junk, r'(?i)u5=([\d|]*)'), '|') AS value
FROM data  

输出如下

id  value    
1   205478499    
    205477661    
2   205478499    
    205477661    
    234567899