I'm trying to break a location.hash into an array using a RegEx. I can't for the life of me get the RegEx right.
the location.hash can be either "#/A/B/C/D" or "#/A/B/C/D/"
and must break down into "A", "B", "C", "D".
I'm trying to break a location.hash into an array using a RegEx. I can't for the life of me get the RegEx right.
the location.hash can be either "#/A/B/C/D" or "#/A/B/C/D/"
and must break down into "A", "B", "C", "D".
Doesn't get much easier than:
var a = location.hash.split('/');
You still get #
as first result, but you can easily remove or ignore it.
I'd trim the leading/trailing guff then split on /
:
location.hash.replace(/^#\/|\/$/g, '').split('/');