从特定字符 BigQuery 之间的 url 中获取值

Grab the values from url that is in between specific characters BigQuery

我需要解析 url 以获取 .com/ 之后和下一个 / 字符之前的值。我的数据如下所示:

url
https://www.delish.com/food-news/news/jdhgkjdf/100-years-of-christmas
https://www.delish.com/food-news/news/100-years-of-christmas

期望的输出是:

new_string
food-news
food-news

我试过以下方法:

SPLIT(url, '/')[SAFE_OFFSET(ARRAY_LENGTH(SPLIT(url, '/')) - 4)] AS new string

但是因为 URL 不一致,有时它抓取 food_news,有时它抓取 www.delish.com,这就是偏移量在这种特殊情况下不起作用的原因。

SPLIT(url, '/')[SAFE_OFFSET(ARRAY_LENGTH(SPLIT(b.page_link, '.com/')) +1)] AS new_string

下面使用

regexp_extract(url, net.host(url) || r'/([^/]+)')