I am trying to map the hash of a url using Javascript.
Yes, do not do this. Every browser has the perfect URL parser built in. Set href for the location object ( window.location or link), and you can read / write URLs from the properties hostname , pathname , search , hash , etc.
var a= document.createElement('a'); a.href= 'http://www.example.com/foo#bar#bar'; alert(a.hash); // #bar#bar
If you put the / -separated path in the hash code, I suggest hash.split('/') follow.
Regarding regex, both versions work the same for me. The final // does not cause a comment. If you just want to calm some dodgy syntax highlighting, you can potentially avoid / before \x2F .
bobince
source share