【发布时间】:2021-01-19 05:27:13
【问题描述】:
我想使用 BigQuery 提取位于匹配字符右侧的所有字符。 例如: 假设我想提取 '-' 右边的所有字符 那么:
- happy-holiday will give holiday
- gogoa-gone 会放弃的
谁能帮我解决这个问题
【问题讨论】:
标签: google-bigquery data-analysis
我想使用 BigQuery 提取位于匹配字符右侧的所有字符。 例如: 假设我想提取 '-' 右边的所有字符 那么:
谁能帮我解决这个问题
【问题讨论】:
标签: google-bigquery data-analysis
试试SPLIT:
SELECT SPLIT("happy-holiday will give holiday", "-")[OFFSET(1)]
SELECT REGEXP_EXTRACT("happy-holiday will give holiday", r"-(.*)")
【讨论】:
Sergey 提到的 SPLIT 效果很好.. 或者你可以用老派的方式来做 :)
WITH sample_data AS (
SELECT 'happy-holiday' as text
UNION ALL
SELECT 'gogoa-gone' as text
UNION ALL
SELECT 'hello-world' as text
UNION ALL
SELECT 'i-am-back' as text
UNION ALL
SELECT 'hey-whatever is after the dash' as text
)
SELECT text
, instr(text, '-', -1) as dash_position
, substr(text, instr(text, '-', -1)+1, length(text)) as substr
FROM sample_data
结果:
TEXT DASH_POSITION SUBSTR
---------------------------------------------------------------------------
happy-holiday 6 holiday
gogoa-gone 6 gone
hello-world 6 world
i-am-back 5 back
hey-whatever is after the dash 4 whatever is after the dash
【讨论】: