Sam
Sam

Reputation: 7058

Replace @mention with link

I am looking to replace any @mention in a string with <a href="http://twitter.com/mention">@mention</a> using Javascript or jQuery. I have the function from the second answer of How to replace plain URLs with links? and am simply looking to add a further replacePattern

Upvotes: 2

Views: 2307

Answers (1)

Joseph Silber
Joseph Silber

Reputation: 219938

function replaceAtMentionsWithLinks ( text ) {
    return text.replace(/@([a-z\d_]+)/ig, '<a href="http://twitter.com/$1">@$1</a>'); 
}

See it here in action: http://jsfiddle.net/h6HMY/

Upvotes: 9

Related Questions