var myregexp = /[?&]PageID=(\d+)/i;
var match = myregexp.exec(url);
if (match != null) {
//This is if your match it successful
result = match[1];
} else {
//This is if url doesn't match
result = "";
}
This one will work regardless of where PageID is. It will match
- sitename.com/Default.aspx?PageID=13078494
- anything.org/Default.aspx?PageID=13078494
- sitename.com/Default.aspx?foo=bar&PageID=13078494
- sitename.com/Default.html?foo=bar&PageID=13078494&bar=foo
- Default.html?foo=bar&PageID=13078494&bar=foo
Importantly, it WON'T match
- sitename.com/Default.aspx?NotThePageID=13078494
Or without the checking, simply
url.match(/[?&]PageID=(\d+)/i)[1], but I'd advice against that unless your SURE it will always match.