java - 从字符串中提取哈希标签

标签 java extract

<分区>

我想提取 String# 字符之后的所有单词,并将它们存储在 String[] 数组中。

例如,如果这是我的 String...

"Array is the most #important thing in any programming #language"

然后我想将下面的单词提取到一个String[]数组中...

"important"
"language"

有人可以提供实现此目标的建议。

最佳答案

试试这个-

String str="#important thing in #any programming #7 #& ";
Pattern MY_PATTERN = Pattern.compile("#(\\S+)");
Matcher mat = MY_PATTERN.matcher(str);
List<String> strs=new ArrayList<String>();
while (mat.find()) {
  //System.out.println(mat.group(1));
  strs.add(mat.group(1));
}

输出-

important
any
7
& 

关于java - 从字符串中提取哈希标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10432543/

相关文章:

java - Mybatis XML 与注解

java - 分配的元空间大于 MaxMetaspaceSize

excel - VBA:提取列直到为空,在下一张表中重复

c# - 如何提取对话框选择的 RAR 文件

JAVA,检索值时出现SQL异常

java - Mockito: stub 深度有多深?

java - 磁盘上的spring代码配置addResourceLocations

linux - 在Linux上提取分割的.tar文件,需要单独解密

python - 使用 7zip 解压 .rar 文件但找不到压缩包

python - 如何从Python中的文本中提取二维年份?