最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Replace @mention with link - Stack Overflow

programmeradmin2浏览0评论

I am looking to replace any @mention in a string with <a href="">@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

I am looking to replace any @mention in a string with <a href="http://twitter./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

Share Improve this question edited May 23, 2017 at 10:33 CommunityBot 11 silver badge asked Jun 2, 2013 at 3:49 SamSam 7,0988 gold badges37 silver badges64 bronze badges
Add a ment  | 

1 Answer 1

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

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

发布评论

评论列表(0)

  1. 暂无评论