我有这个漂亮的函数,但我需要对其进行自定义以仅返回与正则表达式匹配的项目数组。所以结果#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());