想从Notepad ++或Excel的超链接中删除nth“/”后的所有内容

我需要一些帮助:寻找一种方法来删除超链接中“/”的第n次出现(最可能是第4或第5次)之后的所有内容。 例如,如果我有

https://www.forbes.com/forbes/welcome/?toURL=https://forbes.com/&refURL=&referrer= 

我想要的输出是:

 https://www.forbes.com/forbes/welcome/ 

此外,如果一个链接只有<4“/”,我想保持一切。 提前致谢!!

使用Notepad ++:

  • Ctrl + H
  • find: ^((?:[^/]*/){5}).*$
  • replace为: $1
  • 检查包裹
  • 检查正则expression式
  • 不要检查. matches newline . matches newline
  • 全部replace

说明:

 ^ : begining of lin ( : start group 1 (?: : start non capture group [^/]* : 0 or more any character that is not a slash / : a slash ){5} : group must appear 5 times ) : end group 1 .* : 0 or more any character $ : end of line 

替代:

 $1 : content of group 1 (ie. everything before the 5th slash) 

给定示例的结果:

 https://www.forbes.com/forbes/welcome/ 

非常简单的公式,虽然我同意@Scott Holtzman,你应该在发布问题之前展示一些努力。 在Excel中,如果链接位于单元格A1中,请在单元格B1input此公式。

 =IFERROR(LEFT(SUBSTITUTE(A1,"/","~~~~",5),FIND("~~~~",SUBSTITUTE(A1,"/","~~~~",5),1)-1)&"/",A1) 

在这里输入图像说明