Reputation: 119
I need to get the last digit (the last number) from the string which contains a link.
For example from the link below, I should return the number 51
http://radio-pendimi.com/website/index.php/artikuj/31-miresjellja-edukata-fetare/51-permbaje-gjuhen-tende
or from the followinig one:
http://radio-pendimi.com/website/index.php/artikuj/30-ilace-per-zemren-rukja/9137-jeta-me-allahun-ka-shije-tjeter,
number 9137
should be returned
$.each (path.item,function(key,val){
//id_temp= val.guid.content.replace(/[^0-9 ]/g, '');
id=val.guid.content;
var tempDiv = $('<div id="tempDiv">' + val.description + '</div>');
introImg = tempDiv.find("img:first").css({"width":"100%","border-bottom":"4px solid #cd1d1d"});
var staticImg = '<img src="images/pendimi-logo.png" style="width:100%;border-bottom:4px solid #cd1d1d;background:#444"/>';
output+='<div id="lajme">ID = '+id;
output+= '<p style="height:15px;"><span style="font-size:13px;font-family:Bitter;color:gray;padding-left:7px">Kategoria: ' + val.category + '</span><span style="float:right;font-size:13px;font-family:Bitter;color:gray;margin:3px"></p>';
output+='<a href="#artikujtFetar-full" onclick="showPostArtikujtFetar('+ id +')" style="text-decoration:none">';
output+= '<p style="margin:0px">' + $('<div>').append(introImg).html() + '</p>';
output+='<h3 style="word-wrap:break-word;font-family:Bitter;font-size:16px;color:#444;text-align:center;line-height:30px;">'+ val.title +'</h3>';
output+='</a>';
output+='</div>';
output+='<div style="height:15px;background:rgb(210, 215, 217);"></div>';
return key<3;
}); //lexo cdo element 1 nga 1
$('#shfaqArtikujtFetar').html(output);
PS: I need the usage to be in jQuery or JavaScript. It could be a Regex or a function, just let it return the result I need.
Upvotes: 0
Views: 60
Reputation: 9235
Another solution
\d+(?!.*\d)
Usage
var s = "http://radio-pendimi.com/website/index.php/artikuj/31-miresjellja-edukata-fetare/51-permbaje-gjuhen-tende";
var p = /\d+(?!.*\d)/;
var m = s.match(p);
console.log(m[0]); // 51
Upvotes: 1
Reputation: 67968
.*\/(\d+)
This will give the required ans.
See demo.
http://regex101.com/r/cH8vN2/3
Upvotes: 1