Javascript String parseHashtag()
String.prototype.parseHashtag = function() { return this.replace(/([^A-Za-z0-9_\u4E00-\u9FA5]#|^#)([#A-Za-z0-9_\u4E00-\u9FA5]+)/g, function($0,$1,$2) { var t =$2;/*from w ww . ja va 2 s . com*/ if(t.indexOf('#')!=-1){ return $0; } t = '#'+t; var tag = t.replace("#","%23") return $1.substr(0,$1.length-1)+t.link("http://search.twitter.com/search?q="+tag); }); }; test = "#Simon is#writing ?#? a #post #??,#?? about #??... #c#twitter, #???-??? and parsing hashtags as URLs"; document.writeln(test.parseHashtag())
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); });/*from w ww . j av a 2s.co m*/ };
String.prototype.parseHashtag = function() { return this.replace(/[#]+[A-Za-z0-9-_]+/g, function(t) { var tag = t.replace("#", "%23") return t.link("https://twitter.com/hashtag/" + tag + "?src=hash"); });// w w w . j a v a2 s. co m };
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); });/*from ww w. jav a 2 s. c o m*/ }; function linkify(text) { return text.parseURL().parseUsername().parseHashtag(); }
String.prototype.parseHashtag = function() { return this.replace(/[#]+[A-Za-z0-9-_]+/g, function(t) { var tag = t.replace("#","%23") var href="http://search.twitter.com/search?q="+tag var link="<a target='_blank' href='"+href+"'>"+t+"</a>" return link;/*from w w w. j a v a2 s . c o m*/ }); };