Search code examples
regexfilemaker

RegEx match strings with more than 5 Slashs


I need to find URLs with more then 5 slashs and ignore trailing slash.

Like match

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

Not matching

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

Solution

  • This one does the job:

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

    Explanation:

    ^               : 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