我已經有了兩個正則表達式的功能解析網址,並從JSON Twitter的響應回覆,但我試圖把它擴大到解析哈希標籤藏漢但我正在逐漸顯示在主題標籤的。安迪undefined
:JavaScript的散列標籤解析功能
// process links, reply and hash tags
tweet = tweet.replace(/(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig, function(url) {
return '<a href="'+url+'">'+url+'</a>';
}).replace(/[email protected]([_a-z0-9]+)/ig, function(reply) {
return reply.charAt(0)+'<a href="http://twitter.com/'+reply.substring(1)+'">'+reply.substring(1)+'</a>';
}).replace(/#([a-zA-Z0-9]+)/g), function(hash) {
return '<a class="hashtag" target="_blank" href="http://twitter.com/#search?q='+$1+'">#'+$1+'</a>';
};
任何指向我要去哪裏的錯?
'tweet'的內容是什麼? – SilentGhost
tweet是'另一個垃圾推文#測試'和輸出是'另一個垃圾推文undefined' – martincarlin87
爲什麼你不使用'哈希'變量? – SilentGhost