javascript中与正则表达式匹配的主题标签边界 [英] hashtag boundaries matching regex in javascript
本文介绍了javascript中与正则表达式匹配的主题标签边界的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试匹配JavaScript字符串中的一组标签或单词.
I'm trying to match a set of hashtags or words in a javascript string.
(#hashtag|word)
几乎可以做到,除了我想考虑单词边界.
almost does it, except I'd like to consider word boundaries.
\b(#hashtag|word)\b
与开头的单词边界不匹配,因为#"当然不是单词字符.
doesn't match the beginning word boundary, since of course '#' is not a word character.
理想情况下,我希望具有与主题标签匹配的"\ b"锚.有什么主意吗?
ideally i'd like to have something like a '\b' anchor that matches hashtags. Any idea?
推荐答案
在括号内插入单词边界怎么办?
What about insert word boundary inside the parenths :
/(#\bhashtag|\bword)\b/
这篇关于javascript中与正则表达式匹配的主题标签边界的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文