<分区>
我想提取 String
中 #
字符之后的所有单词,并将它们存储在 String[]
数组中。
例如,如果这是我的 String
...
"Array is the most #important thing in any programming #language"
然后我想将下面的单词提取到一个String[]
数组中...
"important"
"language"
有人可以提供实现此目标的建议。
<分区>
我想提取 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/