Create array of regex matches

后端 未结 6 1618
醉话见心
醉话见心 2020-11-22 16:21

In Java, I am trying to return all regex matches to an array but it seems that you can only check whether the pattern matches something or not (boolean).

How can I u

6条回答
  •  一个人的身影
    2020-11-22 16:47

            Set keyList = new HashSet();
            Pattern regex = Pattern.compile("#\\{(.*?)\\}");
            Matcher matcher = regex.matcher("Content goes here");
            while(matcher.find()) {
                keyList.add(matcher.group(1)); 
            }
            return keyList;
    

提交回复
热议问题