开发者

RegEx : Perfect hash tag regex

开发者 https://www.devze.com 2023-02-21 00:08 出处:网络
This is what I have so far: \\s#([^ ]*) Example : http://regexr.com?2te3d It works pretty well except hashtags at the beginning of strings don\'开发者_运维问答t get picked up by my RegEx.

This is what I have so far:

\s#([^ ]*)

Example : http://regexr.com?2te3d

It works pretty well except hashtags at the beginning of strings don'开发者_运维问答t get picked up by my RegEx.

How should I modify it to pick these ones up as well? The \b command doesn't seem to work the same way as it does with normal words.


If it is just about the beginning of the string, you could do:

(^|\s)#([^ ]*)


Try this regex: \B#([^ ]+) It matches all hashtags except the one in the URL which i guess shouldn't be matched


Given this input: #first #second # #third #weird#tag #with-minus #

This: /(^|\s)#([^\s]+)/g will skip empty #'s and will only match:

  • #first
  • #second
  • #third
  • #weird#tag
  • #with-minus
0

精彩评论

暂无评论...
验证码 换一张
取 消