如何用Google Sheets替换URL的特定部分

huangapple go评论62阅读模式
英文:

How can I replace a specific part of an URL with Google Sheets

问题

I tried a lot of things with Regexextract and Substitute but I can't get it to work so I hope someone can help me on this.

We have a link structure with the category name in the second '/' part of the url. In Google Sheets I want to replace this with the category name: 'dagdeals'. How can I do this? Just to give an example:

https://trips.holidayguru.nl/packages/nederland/cd4ea4f1-3189-4a60-8ad1-60e1a15bdccf/
Here 'nederland' should be replaced with 'dagdeals'

https://trips.holidayguru.nl/packages/weekendje-weg/4fbce498-cb07-4032-94e4-903bb29af772/
Here 'weekendje-weg' should be replaced with 'dagdeals'

Thank you!

英文:

I tried a lot of things with Regexextract and Substitute but I can't get it to work so I hope someone can help me on this.

We have a link structure with the category name in the second '/ /' part of the url. In Google Sheets I want to replace this with the category name: 'dagdeals'. How can I do this? Just to give an example:

https://trips.holidayguru.nl/packages/nederland/cd4ea4f1-3189-4a60-8ad1-60e1a15bdccf/
Here 'nederland' should be replaced with 'dagdeals'

https://trips.holidayguru.nl/packages/weekendje-weg/4fbce498-cb07-4032-94e4-903bb29af772/
Here 'weekendje-weg' should be replaced with 'dagdeals'

Thank you!

答案1

得分: 2

你可以尝试以下代码:

=index(substitute(A:A,ifna(regexextract(A:A,"(?:/([^/]+)){3}"),"dagdeals")))

或者

=index(ifna(regexreplace(A:A,"(//.?/.?/)([^/]+)(.*)&","$1dagdeals$3")))

英文:

You may try:

=index(substitute(A:A,ifna(regexextract(A:A,"(?:/([^/]+)){3}")),"dagdeals"))

OR

=index(ifna(regexreplace(A:A,"(//.*?/.*?/)([^/]+)(.*)","$1dagdeals$3")))

如何用Google Sheets替换URL的特定部分

huangapple
  • 本文由 发表于 2023年5月11日 18:50:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/76226818.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定