I'm currently linkifying hashtags using regex like this:
var text = "#sun #summer";
text = text.replace(/(^|\s)#(\S+)/g, '$1<a href="/$2">#$2</a>');
output:
"#<a href="/sun">sun</a> #<a href="/summer">summer</a>"
this works fine, but sometimes people add hashtags without spaces in between them, so something like this: "#sun#summer"
how do I linkify this type of hashtags without spaces?
I tried this:
var text = "#sun#summer";
text = text.replace(/(^|.)#(.|\S+)/g, '$1<a href="/$2">#$2</a>');
output:
"<a href="/s">#s</a>un<a href="/s">#s</a>ummer"
but only works for one char after #