首页 > 解决方案 > 需要用于 URL 检查的正则表达式?

问题描述

我需要一个 URL 字符串的正则表达式。

我的 URL 字符串敌人喜欢

https 冒号 // 字符串点字符串/字符串(中间不包含任何空格)

标签: sqlregexgoogle-bigquerygcloud

解决方案


下面是 BigQuery 标准 SQL 的示例

#standardSQL
WITH `project.dataset.table` AS (
  SELECT 'check this link http://www.example.com/products?id=1&page=2' tweet UNION ALL
  SELECT 'http://www.example.com/products?id=1&page=2 this link is awesome' tweet UNION ALL
  SELECT 'the link http://www.example.com/products?id=1&page=2 is awesome' tweet 

)
SELECT REGEXP_REPLACE(tweet, r"(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]+", '') clean_tweet
FROM `project.dataset.table`  

结果

Row clean_tweet  
1   check this link  
2   this link is awesome     
3   the link is awesome  

推荐阅读