Consider a scenario where you have a string consisting of terms separated by slashes ('/'
), like this:
ab/c/def
Your goal is to identify all the prefixes of this string up to a slash or the end of the string. For the given example, the expected results would be:
ab
ab/c
ab/c/def
You may have tried a regular expression such as: /^(.*)[\/$]/
, which provided only a single match - ab/c/
with the captured group ab/c
.
UPDATE :
Although using split
can achieve this easily, a solution involving RegExp
is specifically sought after.