View Full Version : Resolved RegExp URI Hash

07-18-2011, 09:32 PM
Hey there, I'm looking to have some functionality similar to Twitter in that pages are loaded through ajax depending on the path that is shown in the URI hash.

For example: http://twitter.com/#!/BarackObama/following

I could just split the string by "/" but I want it to work if you enter a bunch of forward slashes as well, or none at all (only for the first forward slash), here's an example:


The hash would be broken down into multiple parts, the first parameter (ie. BarackObama) would be the first returned value from the match, the second would be the rest of the parameters.

Here are examples of what the hash would be, and what I would like in return.

1. http://twitter.com/#/BarackObama/following/test
2. http://twitter.com/#///////////BarackObama/following
3. http://twitter.com/#BarackObama

Returned value from RegExp match:
1. BarackObama,following/test
2. BarackObama,following
3. BarackObama

Hope that makes it pretty clear. I also have this so far, but it returns both a comma separated list, but also the original string.


07-18-2011, 09:42 PM
Try this:

var myURL = 'put URL in here';
var myMatch = myURL.match(/#\/*([A-z0-9]+)\/*(.*)$/);
if(myMatch) {
for(i=1; i<myMatch.length; i++) {

07-18-2011, 09:49 PM
ERM, edit: I'm still having the same problem as before, the first returned value is the entire string. Edit again: Nevermind, I see you have to start at key #1 to return the first value, as opposed to #0.