EDIT: I probably should have mentioned that this is for a Backbone.js route. Splitting it is not an option.
With the following string:
!/example/c/0/0/0/0
I am trying to use “match()” to extract the values between the slashes. My issue is that the last item(“/0”) may not always be in the string. This is what I currently have:
'!/example/c/0/0/0/0'.match(/^!(\/[A-z0-9\-_]+|)\/c\/([0-9]+)\/([0-9]+)\/([0-9]+/)
This returns an array with ‘example’, ‘0’, ‘0’, ‘0’ if example is present and ”, ‘0’, ‘0’, ‘0’ if example is not present… So in the end the result I would like to see is:
'example', '0', '0', '0', ''
when the last item isn’t present or:
'example', '0', '0', '0', '0'
when it is present. So basically it’s the slash before the last item that’s getting me! Any help would be greatly appreciated.
Prefer splitting because you know your delimiter, this will be easier !