I'm trying to get the first, second, or third value of a string in bigquery using the regex_extract function.
The string looks like this
"testimage International,testimageinternational,002533336564114VoIdiAA"
I've been googling around and i'm struggling to get an appropriate regex function.
This is the closest I've gotten REGEXP_EXTRACT(string, r'[^,]+1') as x
However although it works great if the string is test,test1,test2
it doesn't work on the actual string. Any explanation of where i'm going wrong would be super appreciated.
答案 0 :(得分:1)
Below is for BigQuery Standard SQL
Based on example in your question and suggested regex - I feel you might want to consider simply using SPLIT() as below
#standardSQL
WITH t AS (
SELECT 'testimage International,testimageinternational,002533336564114VoIdiAA' str
)
SELECT
SPLIT(str, ',')[SAFE_OFFSET(0)] AS first,
SPLIT(str, ',')[SAFE_OFFSET(1)] AS second,
SPLIT(str, ',')[SAFE_OFFSET(2)] AS third
FROM t
with result
Row first second third
1 testimage International testimageinternational 002533336564114VoIdiAA