首页 > 解决方案 > RegEx 匹配超过 5 个斜杠的字符串

问题描述

我需要找到超过 5 个斜杠并忽略尾随斜杠的 URL。

喜欢比赛

https://www.url.com/cat1/cat2/cat3/cat4/

不匹配

https://www.url.com/cat1/cat2/cat3/

标签: regexfilemaker

解决方案


这个做的工作:

^(?:[^/\r\n]*/){6,}[^/\r\n]+

解释:

^               : beginning of line
  (?:           : start non capture group
    [^/\r\n]*   : 0 or more any character that is not a slash or a linebreak
    /           : 1 slash
  ){6,}         : end group, must appear 6 or more times
  [^/\r\n]+     : 1 or more any character that is not a slash or a linebreak

推荐阅读