I'm implementing hashtags in my app i use ionic angularjs, im trying to match what's in the string and wrap them around an anchor in the string have a data model like this:
{id:1, tags:["cool","love"], message: "i am #cool and i #love you"}
Lets say for example view is like this:
<p> i am #cool and i #love you</p>
How do i implement this
Welcome to the magic of Regex!
Regex is your one-stop shop for text matching! Have a look at in action:
function linkHashtag(text) {
return text.replace(/#[a-z]+/g, "<a href=\"/api/hastag/$&">$&</a>\")
}
When fed text with hashtags in it, it will replace them with a link to the hashtag specific url! Isn't that just dandy!
Hope this is useful for you