This ugliness will do what you want (though you may need to strip the ending /, if you don’t want it:
\/\/[^\/]+(?<pathnoendingnumbers>\/[a-zA-Z-_][-_\w]+(\/[a-zA-Z-_][-_\w]+(\/[a-zA-Z-_][-_\w]+(\/[a-zA-Z-_][-_\w]+(\/[a-zA-Z-_][-_\w]+)?)?)?)?)[\/\d$]?
It’s a 206-step match, which may be improbable – but it’s pretty efficient as is
from User warren – Stack Overflow https://stackoverflow.com/questions/68479024/need-to-write-a-regex-to-extract-path-for-first-5-slashes-or-up-to-a-number-for/68488077#68488077
via IFTTT