我需要從包含鏈接的字符串中獲取最後一位數字(最後一個數字)。 例如從下面的鏈接,我應該回到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