📅  最后修改于: 2022-03-11 14:59:42.495000             🧑  作者: Mango
public static void main(String[] args) {
final String str = "apple helloorange pear ";
System.out.println(Arrays.toString(getTagValues(str).toArray())); // Prints [apple, orange, pear]
}
private static final Pattern TAG_REGEX = Pattern.compile("(.+?) ", Pattern.DOTALL);
private static List getTagValues(final String str) {
final List tagValues = new ArrayList();
final Matcher matcher = TAG_REGEX.matcher(str);
while (matcher.find()) {
tagValues.add(matcher.group(1));
}
return tagValues;
}