Java Regex - 从String中提取Hashtags [英] Java Regex - Extract Hashtags from String

查看:147
本文介绍了Java Regex - 从String中提取Hashtags的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

需要从Java中的源字符串中提取出标签字符串。任何想法/例子?

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

谢谢,
Sri

Thanks, Sri

推荐答案

这是我正在使用的(它也处理UTF-8标签,而不仅仅是ASCII):

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-_]+)");

顺便说一下,你应该能够从推文实体中获取主题标签( include_entities = true

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

这篇关于Java Regex - 从String中提取Hashtags的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆