首页 > 解决方案 > 将单元格中的文本限制在找到的倒数第二条

问题描述

链接由不同数量的条组成,但最后一个条和倒数第二条之间包含的内容对我不感兴趣,我可以使用什么公式?

原来的:

https://int.soccerway.com/national/czech-republic/czech-liga/20192020/championship-round/r54505/
https://int.soccerway.com/national/england/championship/20192020/regular-season/r53782/
https://int.soccerway.com/national/finland/veikkausliiga/2020/regular-season/r56520/
https://int.soccerway.com/national/germany/play-offs-12/20192020/s17666/
https://int.soccerway.com/national/germany/play-offs-23/20192020/s17670/
https://int.soccerway.com/national/norway/1-division/2020/regular-season/r56858/
https://int.soccerway.com/national/sweden/superettan/2020/s18293/
https://int.soccerway.com/national/united-states/nwsl-challenge-cup/2020/preliminary-round/r58293/

预期结果:

https://int.soccerway.com/national/czech-republic/czech-liga/20192020/championship-round/
https://int.soccerway.com/national/england/championship/20192020/regular-season/
https://int.soccerway.com/national/finland/veikkausliiga/2020/regular-season/
https://int.soccerway.com/national/germany/play-offs-12/20192020/
https://int.soccerway.com/national/germany/play-offs-23/20192020/
https://int.soccerway.com/national/norway/1-division/2020/regular-season/
https://int.soccerway.com/national/sweden/superettan/2020/
https://int.soccerway.com/national/united-states/nwsl-challenge-cup/2020/preliminary-round/

测试失败:

REGEXEXTRACT('Página1'!T2:T,
REGEXREPLACE('Página1'!T2:T,"(https?:\/\/([\w.-]+\/){6})","($1)"))

我测试的模型不起作用,因为倒数第二条并不总是在位置 6,所以它不能满足我的需要。

标签: regexurlgoogle-sheetsgoogle-sheets-formulaarray-formulas

解决方案


您可以匹配最后一个文本,/并在第 1 组中捕获所有之前的内容。

在替换使用组 1 中。

例如单个条目=REGEXREPLACE(A1, "(https?://\S+/)[^\s/]+/", "$1")

(https?://\S+/)[^\s/]+/

正则表达式演示


推荐阅读