How to get the last segment with regular expression?
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_'+i开发者_开发百科d;
Could anyone tell me how to code this?
var id = this.href.match(/[^\/]*$/)
this.id = 'delete_link_' + id;
Why use regex?
var parts=this.href.split("/");
var id = parts[parts.length - 1];
this.id='delete_link_'+id;
Regex is overkill here.
var s = "http://127.0.0.1/ci/index.php/admin/menus/edit/24";
s.substring(s.lastIndexOf("/")+1);
"http://127.0.0.1/ci/index.php/admin/menus/edit/24".match(/^.*\/([^\/]+)$/)[1]
精彩评论