我需要幫助識別純文本句子中的twitter句柄(我認爲它被稱爲句柄..),並在句柄周圍包裹一個span標籤。在純文本句子中識別twitter句柄
所以,如果我有這樣構成的句子:
I can't wait to watch the 2012 London Olympic Games! @london2012
我需要找到手感和環繞它的跨度標籤:
I can't wait to watch the 2012 London Olympic Games! <span>@london2012</span>
這是我嘗試使用:
function findHandle(text) {
var handle = text.substr(text.indexOf("@"), text.indexOf(" "));
return text.replace(handle, "<span>" + handle + "</span>");
}
我的代碼沒有按計劃工作。最好的辦法是什麼?
如果手柄後沒有空間會怎麼樣? – 2012-08-07 19:48:02
這是我碰到的問題之一。 – 2012-08-07 19:53:58