I have following regex expression
(.*[\/])
This will match /path/tooo/url/
from this string
/path/tooo/url/blablabla-xxxxx
My question is how to modify regex to match
/path/tooo/url
(without last /)
Thank you.
Here's one approach. Match each instance of a forward-slash followed by one or more characters that are not a forward-slash, then match one or more instances of that. Keep matching until we find an instance of a forward-slash followed by only non-forward-slash characters (negative lookahead).
((?:\/[^\/]+)+)(?=\/[^\/]+)
I put a capturing group around the whole thing because it appears you want to capture the result in a capturing group (your regex is wrapped in parens).
I'm using a non-capturing group for the inner regex: (?:) because we don't need to capture this group. See: What is a non-capturing group? What does a question mark followed by a colon (?:) mean?