[英]Need a regex for URL check?
我需要一个 URL 字符串的正则表达式。
我的 URL 字符串就像
https 冒号 // 字符串点字符串/字符串(中间不包含任何空格)
从https://gist.github.com/jacksonfdam/3000275我发现:
^http(s)?:\/\/((\d+\.\d+\.\d+\.\d+)|(([\w-]+\.)+([a-z,A-Z][\w-]*)))(:[1-9][0-9]*)?(\/([\w-.\/:%+@&=]+[\w- .\/?:%+@&=]*)?)?(#(.*))?$/i
下面是 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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.