I'm able to match a part of the URL string to the specified format. This looks like this:
/foo/firstName[firstId]/optional1[oId1]/optional2[oId2]/…
where name[id] need to be together (like not just name or [id]) but only firstName[firstId] is mandatory and there can be up to six optional entries.
I currently match such an entry with
/(?:([^\[]+)\[([^\]]+)\])/
which works well standalone, as you can see in this example but not with the complete URL (example). In the second version, the intermediate matches are overwritten and only the last one stays.
How can I solve that problem?
EDIT:
Because I don't know if the dear reader understands my question, I created a simplified version.
Given the Strings:
/foo/x/y/z
/foo/x/y
/foo/x
I now want to match all three of them and to get back x, y and z.
I can use
^\/foo(?:\/(\w))+
to match the whole string. But I get only z (or only y or only x respectively) back. How do I change that?