2017-03-09 218 views

回答

2

參見下面的例子

#standardSQL 
WITH yourTable AS (
    SELECT '756-1__6565656565656, tagtype**unmapped,domain**www.sport.com,userarriveddirectly**False' AS Site_Data 
) 
SELECT 
    REGEXP_EXTRACT(Site_Data, r'domain\*\*(.*)\*\*') AS x, 
    Site_Data 
FROM yourTable 
+0

10x Mikkhai!有效 :) –

2

是否所有的琴絃有格式?假設您總是需要**定界符後面的第三個字符串,有幾個不同的選項。

1)使用SPLIT,如:

#standardSQL 
WITH SampleData AS (
    SELECT '756-1__67648582789116,tagtype**unmapped,domain**www.sport.com,userarriveddirectly**False' AS site_data 
) 
SELECT SPLIT(site_data, '**')[OFFSET(2)] AS visit_type 
FROM SampleData; 

2)使用REGEXP_EXTRACT,如:

#standardSQL 
WITH SampleData AS (
    SELECT '756-1__67648582789116,tagtype**unmapped,domain**www.sport.com,userarriveddirectly**False' AS site_data 
) 
SELECT REGEXP_EXTRACT(site_data, r'[^\*]+\*\*[^\*]+\*\*([^\*]+)') AS visit_type 
FROM SampleData; 

採取此基礎上更進一步,如果你想分裂域和到達類型,您可以再次使用SPLIT

#standardSQL 
WITH SampleData AS (
    SELECT '756-1__67648582789116,tagtype**unmapped,domain**www.sport.com,userarriveddirectly**False' AS site_data 
) 
SELECT 
    SPLIT(visit_type)[OFFSET(0)] AS domain, 
    SPLIT(visit_type)[OFFSET(1)] AS arrival_type 
FROM (
    SELECT SPLIT(site_data, '**')[OFFSET(2)] AS visit_type 
    FROM SampleData 
);