[英]REGEXP_EXTRACT with URL in Hive
I want to extract a word between '/bla-bla-bla/' and 'a12345' in the URL, which is "this-is-the-word"
using regexp_extract in Hive. 我想在Hive中使用regexp_extract提取URL中的“ / bla-bla-bla /”和“ a12345”之间的词,即"this-is-the-word"
。
INPUT: www.website.com/bla-bla-bla/this-is-the-word.a12345.anotherword.blabla 输入:www.website.com/bla-bla-bla/this-is-the-word.a12345.anotherword.blabla
DESIRED OUTPUT: this-is-the-word 期望的输出:这就是字
I've tried below, but none of them worked. 我在下面尝试过,但是没有一个起作用。 What RegEx will achieve my desired output from this input? 哪种RegEx可以从此输入中获得所需的输出?
regexp_extract(URL,'^.*[/]bla[-]bla[-]bla[/]([a-z]+)\\.(a([0-9]+))*$',1)
regexp_extract(URL,'^.*[/]bla-bla-bla[/]([a-z]*)[.]a([0-9]+)*$',1)
You may use 您可以使用
regexp_extract(URL,'^.*/bla-bla-bla/([^/.]+)\.a[0-9].*$', 1)
See this regex demo 观看此正则表达式演示
It matches 它匹配
^
- start of string ^
-字符串的开头 .*
- any 0+ chars other than line break chars, as many as possible .*
-尽可能多的除换行符以外的0+个字符 /bla-bla-bla/
- a literal /bla-bla-bla/
substring /bla-bla-bla/
-文字/bla-bla-bla/
子字符串 ([^/.]+)
- Group 1 (what you will get since the next argument is 1
): 1 or more chars other than /
and .
([^/.]+)
-组1(自下一个参数为1
以来,您会得到什么):1个或更多除/
和以外的字符.
\\.a
- a .a
substring \\.a
一个.a
子字符串 [0-9]
- a digit [0-9]
-一个数字 .*$
- the rest of the string to its end. .*$
-字符串的其余部分。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.