I created a function which parses text and I would like it to return a full link say:
@tw would return <a href="http://www.twitter.com/tw"></a>
rather it returns http://www.twitter.com/tw with no markup. How can I append the tag to include the text tw, and return the markup to the html?
String.prototype.parseUsername = function() {
return this.replace(/[@]+[A-Za-z0-9-_]+/g, function(u) {
var username = u.replace("@","")
var twitter_link = document.createElement("a");
twitter_link.href = "http://www.twitter.com/"+username
twitter_link.target = "_blank"
console.log(twitter_link)
return twitter_link;
});
};
Is this what you’re looking for?