简体   繁体   中英

Ruby Regex - Match words which begin with #

So far I have

def get_hashtags(post)
  words = post.scan(/\#(\w+)/)
end

Which works, however it also gets words like "in#line" whereas I only want words which are beginning with #.

I have tried using \\b but I can't seem to get it right.

Any help would be much appreciated.

Thanks!

我会在#之前使用空白边界

/(?<!\\S)\\#(\\w+)/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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