Reputation: 119
I'm trying to develop a regex that partially matches a certain branch of a path. Not before and not deeper than that level. For example:
/path - no match
/path/subpath - no match
/path/subpath/XYZ-123/subpath - no match
/path/subpath/XYZ-123 - match
So far, I have the following
^\/path\/subpath\/.*$
However, this obviously also matches for /path/subpath/XYZ-123/subpath
which I would like to exclude as well. Note that the path contains characters, numbers and special characters.
Upvotes: 1
Views: 395
Reputation: 626699
You may use
^\/path\/subpath\/[^\/]*$
See the regex demo.
The regex will match
^
- start of a string\/path\/subpath\/
- /path/subpath/
string[^\/]*
- 0 or more chars other than /
$
- end of string.Upvotes: 1