1. 程式人生 > >Java正則表達式-捕獲組

Java正則表達式-捕獲組

mpi matcher java正則 col while 捕獲 result return pat

    private Set<String> getCodes(String s) {
        Set<String> resultSet = new HashSet<>();
        Matcher matcher = codePattern.matcher(s);
        while (matcher.find()) {
            resultSet.add(matcher.group(1));
        }
        return resultSet;
    }

private static Pattern codePattern = Pattern.compile("
\"code\":\"(\\w+)\",");

Java正則表達式-捕獲組