我需要从包含链接的字符串中获取最后一位数字(最后一个数字)。 例如从下面的链接,我应该回到51
如何获取最后/特殊字符后的数字
http://radio-pendimi.com/website/index.php/artikuj/31-miresjellja-edukata-fetare/51-permbaje-gjuhen-tende
或从followinig一个数:
http://radio-pendimi.com/website/index.php/artikuj/30-ilace-per-zemren-rukja/9137-jeta-me-allahun-ka-shije-tjeter,
数9137
应返回
$.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:我需要用法在jQuery或JavaScript中。它可能是一个正则表达式或函数,只是让它返回我需要的结果。
不错的一个!!!!!!!!!!!!!!! – vks 2014-09-04 21:25:07
为什么它给我双值?结果显示为51,51 – albpower 2014-09-04 21:33:47
@albpower好吧,检查更新的答案;并使用'm [0]' – hex494D49 2014-09-04 21:37:12