我正在尝试使用查询从字符串字段(metainfo.body)提取所有url:
select split(regexp_replace(metainfo.body,'.*?((http|ftp|https)://([w_-]+(?:(?:.[w_-]+)+))([w.,@?^=%&:/~+#-]*[w@?^=%&/~+#-]))\n','$1#'),'#')**
它不是只返回url,而是只返回完整的字段。我应该在这个hive查询中改变什么来获得url列表?
,
select regexp_replace('hello hi i am arun http://a.com https://b.com','.*?((http|ftp|https)://([w_-]+(?:(?:.[w_-]+)+))([w.,@?^=%&:/~+#-]*[w@?^=%&/~+#-]))','$1,') as output
输出:
hello hi i am arun http://a.com https://b.com
预期:
http://a.com,https://b.com,
您可以尝试使用不区分大小写。
然后在末尾添加可选的空白s*
或[ trn]*
。
你的正则表达式变成所有ascii没有字类w
:
.*?((?:https?|ftp)://[a-zA-Z0-9_-]+(?:.[a-zA-Z0-9_-]+)+[#%&+-:=?-Z^_a-z~]*[#%&+-/-9=?-Z^_a-z~])s*
REGEXP_REPLACE应该全局替换字符串中所有找到的模式。
我不能测试它,但从一些在线的例子,使用分割像你做
应该工作。
select split(regexp_replace('hello hi i am arun http://a.com https://b.com',
'.*?((?:https?|ftp)://[a-zA-Z0-9_-]+(?:.[a-zA-Z0-9_-]+)+[#%&+-:=?-Z^_a-z~]*[#%&+-/-9=?-Z^_a-z~])s*',
'$1,'), ',');
下面是使用PCRE及其替代品的正则表达式的测试
https://regex101.com/r/lIEvCk/1
其他参考:
here 1
here 2