Please help me with regular expression.
I found this good peace of code:
var ify = function() {
return {
"link": function(t) {
return t.replace(/(^|\s+)(https*\:\/\/\S+[^\.\s+])/g, function(m, m1, link) {
return m1 + '<a href=' + link + '>' + ((link.length > 25) ? link.substr(0, 24) + '...' : link) + '</a>';
});
},
"at": function(t) {
return t.replace(/(^|\s+)\@([a-zA-Z0-9_]{1,15})/g, function(m, m1, m2) {
return m1 + '@<a href="http://twitter.com/' + m2 + '">' + m2 + '</a>';
});
},
"hash": function(t) {
return t.replace(/(^|\s+)\#([a-zA-Z0-9_]+)/g, function(m, m1, m2) {
return m
1 + '#<a href="http://search.twitter.com/search?q=%23' + m2 + '">' + m2 + '</a>';
});
},
"clean": function(tweet) {
return this.hash(this.at(this.link(tweet)));
}
};
}();
But its not working properly.
At first in my page there can be <b>@username</b> and for this cause regex isnt working (i think I need to append this characters "<" and ">" to the "at function". But how?)
At second in "hash" function in my page, in query there can be other non a-zA-Z characters). For example "такие символы" or "ñ" or others. And formatted string will look like #<a href="twitter.com/?q=Catalu">Catalu</a>ña for #Cataluña word
Please help me. Thank you!