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
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With