fork download
  1. import java.util.*;
  2. import java.util.regex.*;
  3.  
  4. class Test
  5. {
  6. public static void main (String[] args) throws java.lang.Exception
  7. {
  8. String text = "asd ${ITEM_NAME} asd ${KEK} asdasd ${ITEM_NAME_2} \n ${ITEM_NAME} asd ${KEK} asdasd ${ITEM_NAME_2}";
  9. Pattern p = Pattern.compile("\\$\\{([^{}]*)}");
  10. Matcher m = p.matcher(text);
  11. Set<String> res = new HashSet<>();
  12. while(m.find()) {
  13. res.add(m.group(1));
  14. }
  15. System.out.println(res);
  16. }
  17. }
Success #stdin #stdout 0.08s 53512KB
stdin
Standard input is empty
stdout
[KEK, ITEM_NAME_2, ITEM_NAME]