我有這個漂亮的功能,但我需要定製它只返回匹配正則表達式的項目數組。所以結果將是#hash1234, #sweetthing,#something_notimportant
有沒有什麼辦法可以使用這個函數來做到這一點?返回匹配的子串數組
String.prototype.parseHashtag = function() {
return this.replace(/[#]+[A-Za-z0-9-_]+/g, function(t) {
var tag = t.replace("#", "%23");
return t.link("http://search.twitter.com/search?q=" + tag);
});
};
var string = '#hash1234 this is another hash: #sweetthing and yet another #something_notimportant';
$('#result').html(string.parseHashtag());
''#hash1234這是另一種散列:#sweetthing和又一#something_notimportant'.match(/ [#] + [A-ZA-Z0-9 -_] + /克)。加入(」 ,「)' – nhahtdh