正则表达式(类似Twitter)标签,允许非ASCII字符 [英] Regex for a (twitter-like) hashtag that allows non-ASCII characters
问题描述
我想要一个正则表达式匹配一个像twitter中那样的简单主题标签(例如#someword)。我希望它也能识别非标准字符(如西班牙语,希伯来语或中文字符)。
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).
这是我最初的正则表达式:(^ | \ | | \b)(#(\ w +))\ b
- >但它无法识别非标准字符。
然后,我尝试使用 XRegExp.js ,虽然有效,但运行速度太慢。
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?
推荐答案
最终我发现了这个: twitter-text.js 有用的链接,这基本上就是twitter如何解决这个问题。
Eventually I found this: twitter-text.js useful link, which is basically how twitter solve this problem.
这篇关于正则表达式(类似Twitter)标签,允许非ASCII字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!