I have a column with values source:destination:city:street:number and i would like to get only the city without : .
How can I do that?
Thanks in advance
How can I do that?
works in both BigQuery dialects: Legacy and Standard SQL
SELECT
REGEXP_EXTRACT('source:destination:city:street:number', r'(?:.+:){2}(.+)(?::.+){2}')
see more for REGEXP_EXTRACT and re2 syntax
if I need the first word after source: for example?
SELECT
REGEXP_EXTRACT('source:destination:city:street:number', r'(?:.+:){1}(.+)(?::.+){3}')
There are many options here for you depends on what exactly you need
Another one is below (BigQuery Legacy SQL)
SELECT
NTH(1, SPLIT(text,':')) AS source,
NTH(2, SPLIT(text,':')) AS destination,
NTH(3, SPLIT(text,':')) AS city,
NTH(4, SPLIT(text,':')) AS street,
NTH(5, SPLIT(text,':')) AS number
FROM (
SELECT 'source:destination:city:street:number' AS text
)