我怎么能达到这样的目的?
example_input = "hi, this is example #input, it has a few #different things going #on. #question"
output ===> [input, different, on, question]
这是我到目前为止所做的:
text.match(/\#.+?\s+/g)
我可以在跟着空白区域进行隔离,但我不确定如何适应,
' '
.
或string end / new line
答案 0 :(得分:1)
/#\w+\b/g
\ b表示边界字符
表示空格,逗号和字符串结尾 使用'\ s',','和'$'
/#\w+(\s?|.|$)/g
这是您可以使用的特殊字符列表(在特殊字符下阅读):
https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/RegExp
答案 1 :(得分:0)
这将在#开始匹配,直到找到空格或标点符号。
/#[^\s\p{P}]+/