The hardest thing about adding #hashtag
support to my little project is the #regex
hell. Thankful for the help, #stackoverflow
A pretty good hashtag regexp is this one. 1-30 characters, has to start with a letter. However, it doesn't handle non-latin characters, so too bad for you people who don't speak American. I don't know of a character class that groks unicode, but if you do I'd love to know about it.
allows HTML in content, you first have to sanitize it to prevent any XSS attacks, then turn it into DOM, then extract the text nodes, and scan each one for hashtags with the above regex. Surround each one you find into an anchor and reassemble the whole thing back to a DOM object and insert that into your page. You have to handle special cases like having punctuation after your #hashtag
, since that's a thing we #do
The strangest thing is why systems like #Friendica
surround hashtags in content they send to other systems with links back to their own site. Why would my users want to see hashtags on your website?