simplified and improved replace patterns

This commit is contained in:
Samuel Reis 2010-09-21 17:19:24 +02:00
parent 54c8a70f8e
commit 25ab48951f

View file

@ -307,13 +307,13 @@ Twittia.prototype.authorizationHeader = function(method, url, params) {
}
function replaceURLWithHTMLLinks(text) {
var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_()|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
var exp = /(\b(https?|ftp|file):\/\/\S+)/ig;
return text.replace(exp,"<a href='$1'>$1</a>");
}
function replaceTwitterLinks(text) {
var username = /(^|[^\/\w])(@)([-A-Z0-9+_\.ÅÖÄÜ]+[^\.,;\W])/ig;
var hash = /(^|[^\/\w])(#)([-A-Z0-9+_\.ÅÖÄÜß]+[^\.,;\W])/ig;
var username = /(^|\s)(@)(\S*)/ig;
var hash = /(^|\s)(#)(\S*)/ig;
text = text.replace(username, "$1$2<a href='http://twitter.com/$3'>$3</a>");
return text.replace(hash, "$1$2<a href='http://search.twitter.com/search?q=%23$3'>$3</a>");
}