vendredi 1 juillet 2016

JavaScript - Find Hashtags in Text and Return With Link

I'm trying to take my text and convert that hashtags to links and different colors than the normal text, but I have no idea how to go about it. I know it has something to do with regex, but I can't seem to get it down. Here's what I have so far, but it doesn't work at all:

function hashtag(text) {
var repl = text.replace(/(^|\W)(#[a-z\d][\w-]*)/ig, '$1<a style = "color: #35ab52">$2</a>');
return(repl);
}

I'd appreciate any help, thanks!




Aucun commentaire:

Enregistrer un commentaire