Java Regex - Extract Hashtags from String

2019-03-29 13:00发布

Need to extract out hashtag Strings from a source String in Java. Any ideas / examples?

Thanks, Sri

1条回答
Evening l夕情丶
2楼-- · 2019-03-29 13:17

Here is what I'm using (it handles UTF-8 tags as well, not only ASCII):

private static final Pattern TAG_PATTERN = 
   Pattern.compile("(?:^|\\s|[\\p{Punct}&&[^/]])(#[\\p{L}0-9-_]+)");

Btw, you should be able to get the hashtags from the tweet entities (include_entities=true)

查看更多
登录 后发表回答