我们可以尝试使用 pattern 进行匹配(?<=\\s|^)#\\S+,它会匹配任何以 开头的单词#,后跟任意数量的非空白字符。String line = "Here is a #hashtag and here is #another has tag.";String pattern = "(?<=\\s|^)#\\S+";Pattern r = Pattern.compile(pattern);Matcher m = r.matcher(line);while (m.find()) { System.out.println(m.group(0));}#hashtag#another