views:

127

answers:

4

I have the following url.

http://127.0.0.1/ci/index.php/admin/menus/edit/24

I want to get 24 from this to use in jquery/javascript.

Something like this.

var id=this.href.replace(/.*=/,'');
this.id='delete_link_'+id;

Could anyone tell me how to code this?

+4  A: 

Why use regex?

var parts=this.href.split("/");
var id = parts[parts.length - 1];
this.id='delete_link_'+id;
Joel Potter
+3  A: 

Regex is overkill here.

var s = "http://127.0.0.1/ci/index.php/admin/menus/edit/24";
s.substring(s.lastIndexOf("/")+1);
jvenema
+3  A: 
var id = this.href.match(/[^\/]*$/)

this.id = 'delete_link_' + id;
Philippe Leybaert
A: 
"http://127.0.0.1/ci/index.php/admin/menus/edit/24".match(/^.*\/([^\/]+)$/)[1]
Anatoliy