數據來源在哪裏?
我懷疑你試圖讀取的數據是爲安全傳輸編碼的。例如,這是空間轉換爲%20的位置。
如果爲true,則需要使用encodeURIComponent()轉換源數據,然後應用您的查找。
這可能工作(雖然我的搜索使用較弱)。我沒有測試代碼,但應該給你方向的想法...
// Collate all href from the document and store in array links
var links=[];
$(document).find("a").each(
function()
{
links.push(encodeURIComponent($(this).prop("href")));
});
// Loop thru array links, perform your search on each element,
// store result in array results
var results=[];
results=links.filter(function(item){
return item.search('/\d(?=\d{4})/g');
});
console.log(results);
https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent