Regex for a (twitter-like) hashtag that allows non-ASCII characters

limlim picture limlim · Jun 5, 2013 · Viewed 8.7k times · Source

I want a regex to match a simple hashtag like that in twitter (e.g. #someword). I want it also to recognize non standard characters (like those in Spanish, Hebrew or Chinese).

This was my initial regex: (^|\s|\b)(#(\w+))\b
--> but it doesn't recognize non standard characters.
Then, I tried using XRegExp.js, which worked, but ran too slowly.

Any suggestions for how to do it?

Answer

limlim picture limlim · Jun 16, 2013

Eventually I found this: twitter-text.js useful link, which is basically how twitter solve this problem.