I'm trying to make navigation on click.
Structure of the site is simple:
site.com/page_2/ site.com/page_3/ ... site.com/page_n/ How to get the URL of the page number?
"site.com/page_123/".match(/(?:page_)(\d+)/)[1]; ?: is not really needed. /page_(\d+)/ is enough.var s = window.location.href; var x = s.split("/"); for(var i = 0; i < x.length; i++) { if(i==x.length-2) { var c = x[i].match(/page_(\d+)/)[1]; } } Automatically gets the Page Number ;) Working Fiddle
x[ x.length - 2 ].match(/page_(\d+)/)[1];?find the fiddle here : http://jsfiddle.net/N2WRS/
var url = "http://www.site.com/page_2/"; // window.location var nurl = url.substr(0, url.lastIndexOf('/')); var finalUrl = nurl.substr(nurl.lastIndexOf('/')+1); alert(finalUrl); // <---this will get you the page_2