Reputation: 4783
var fullHash = window.location.hash;
// fullHash = #search?t=operator&q=Velvet
I need to split the fullHash variable into 3 separate values. One value needs to say 'search', another should say 'operator', and the last should say 'Velvet'. I have tried multiple regex style splits but can't figure it out. If anyone could help me write this I would highly appreciate it!
Upvotes: 0
Views: 562
Reputation: 369394
var fullHash = '#search?t=operator&q=Velvet';
fullHash.match(/[#=][^#=?&]*/g).map(function(m) {
return m.substr(1);
})
// => ["search", "operator", "Velvet"]
Upvotes: 0
Reputation: 59282
Simple solution:
var fullHash = window.location.hash;
fullHash.match(/\w{3,}/g);
Results in:
["search", "operator", "Velvet"]
Upvotes: 3