需要指导使用 REGEXP_REPLACE

Need guidance in using REGEXP_REPLACE

当我 运行 以下 SQL 时,我得到以下结果:

SELECT  distinct id,date,col_t FROM table1
WHERE col_t LIKE '%true%'
OR col_t LIKE '%https%'
OR col_t LIKE '%.html%'
OR col_t LIKE '%.html%'
OR col_t LIKE '%_____%' 
OR col_t LIKE '%null%'

ID     DATE                  COL_T

1     2022-02-02              true
2     2022-02-02              true
3     2022-02-02              PROMOTIONhttps://www.redbus.com/home
4     2022-02-02              google_goog_ob_27pc4https://www.google.com
5     2022-02-02              goog_gl_a1_store_id.html
6     2022-02-02              abc_xyz_def-example_____
7     2022-02-02              elp_car_parking_____
8     2022-02-02              elp1_car2_sum-grill_____
9     2022-02-02              two_abcd_slp_1_null_null_null_null

我想用 NULL 替换真值,用空字符串 '' 替换其他值。 我可以使用 REGEXP_REPLACE 获得所需的输出吗?

我试过使用

REGEXP_REPLACE(COL_T,'\.html|http.*$|_null.*$|____.$|true','')

AS COL_T。但我没有得到准确的 results.The 结果应该如下所示:

    ID     DATE                  COL_T


1     2022-02-02              NULL
2     2022-02-02              NULL
3     2022-02-02              PROMOTION
4     2022-02-02              google_goog_ob_27pc4
5     2022-02-02              goog_gl_a1_store_id
6     2022-02-02              abc_xyz_def-example
7     2022-02-02              elp_car_parking
8     2022-02-02              elp1_car2_sum-grill
9     2022-02-02              two_abcd_slp_1

尝试使用替换: https://docs.snowflake.com/en/sql-reference/functions/replace.html

SELECT  distinct id,
        date,
        CASE 
            WHEN col_t = 'true' then REPLACE(col_t, 'true', '')
            WHEN col_t = '*.html' then REPLACE(col_t, '*.html', '')
            ELSE NULL
        col_t 
FROM table1
WHERE 
        col_t LIKE '%true%'
    OR  col_t LIKE '%https%'
    OR  col_t LIKE '%.html%'
    OR  col_t LIKE '%.html%'
    OR  col_t LIKE '%_____%' 
    OR  col_t LIKE '%null%'