+2  A: 

Try this:

var url = 'http://site/page?object_id=2';
var object_id = url.match(/object_id=(\d+)/)[1];
Tatu Ulmanen
I would just take the $ away, your \d+ should work fine. Also put the + inside the parentheses - `(\d+)`.
Renesis
+1  A: 
foo.match(/(\d+)/);
David Dorward
+2  A: 

If you have the URL in a string:

var str = "http://site/page?other_object_id=10&object_id=2";
var match = str.match(/[?&]object_id=(\d+)/);

if (match) {
  alert(match[1]); // 2
}

If it's the URL of the current page:

var match = location.search.match(/[?&]object_id=(\d+)/);

if (match) {
  alert(match[1]);
}
CMS
SLaks
+3  A: 

Try the following:

/\?(?:.*?&)?object_id=(\d+)/.exec(url)[1]

Unlike other answers, this will correctly handle http://site/page?other_object_id=3&object_id=2

SLaks
Good point, I've updated my answer also :)
CMS