[英]Datastudio: REGEXP_Extract the last part of URL
I am looking to extract the last part of the URL, which looks like this:我希望提取 URL 的最后一部分,如下所示:
https://www.website.com/cat1/cat2/naming/id.html https://www.website.com/cat1/cat2/naming/id.html
I've been trying to edit this:我一直在尝试编辑这个:
REGEXP_EXTRACT(Product URL,'/([\\w-]+)$')
and I'm having a lot of trouble trying to get just id
as the output.我在尝试获取 output 的id
时遇到了很多麻烦。
The output of the above gets me a null value.上面的 output 得到一个 null 值。 If I remove the $
, I get www
.如果我删除$
,我会得到www
。
What is the best way to get the id
, between the last slash and before the .html
?在最后一个斜线和.html
之前获取id
的最佳方法是什么?
You can use您可以使用
REGEXP_EXTRACT(Product URL,'/([^/]*)\\.[^/.]*$')
See the regex demo .请参阅正则表达式演示。
Details细节
/
- a /
char /
- 一个/
字符([^/]*)
- Group 1: any zero or more chars other than /
([^/]*)
- 第 1 组:除/
之外的任何零个或多个字符\.
- a .
- 一个.
char字符[^/.]*
- zero or more chars other than / and
.` [^/.]*
- 除/ and
.` 之外的零个或多个字符$
- end of string. $
- 字符串结尾。 Another possible solution is matching up to the first .
另一种可能的解决方案是匹配第一个.
char:字符:
/([^./]*)[^/]*$
See this regex demo .请参阅此正则表达式演示。 Here, ([^./]*)
captures into Group 1 any zero or more chars other than .
在这里, ([^./]*)
将除 . 以外的任何零个或多个字符捕获到第 1 组.
and /
chars, and then [^/]*$
matches any zero or more chars other than /
till the end of string.和/
字符,然后[^/]*$
匹配除/
之外的任何零个或多个字符,直到字符串结尾。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.