英文:
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")))
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论