📜  你想提取多个命中,试试这个: - 无论代码示例

📅  最后修改于: 2022-03-11 14:59:42.495000             🧑  作者: Mango

代码示例1
public static void main(String[] args) {
    final String str = "applehelloorangepear";
    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;
}