简体   繁体   English

RegEx:完美的哈希标签正则表达式

[英]RegEx : Perfect hash tag regex

This is what I have so far: 这是我到目前为止的内容:

\s#([^ ]*)

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

It works pretty well except hashtags at the beginning of strings don't get picked up by my RegEx. 它工作得很好,除了我的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. \\ b命令的工作方式似乎与普通单词不同。

如果它只是字符串的开头,则可以执行以下操作:

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

试试这个正则表达式: \\B#([^ ]+)它匹配所有标签,但我认为不应该匹配网址中的标签

Given this input: #first #second # #third #weird#tag #with-minus # 给定此输入: #first #second # #third #weird#tag #with-minus #

This: /(^|\\s)#([^\\s]+)/g will skip empty #'s and will only match: 这: /(^|\\s)#([^\\s]+)/g将跳过空#,并且仅匹配:

  • #first #第一
  • #second #第二
  • #third #第三
  • #weird#tag #奇怪#标签
  • #with-minus #with-minus

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM