fork(4) download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4. import java.util.regex.*;
  5.  
  6. class Ideone
  7. {
  8. public static void main (String[] args) throws java.lang.Exception
  9. {
  10. String content = "aba(2)bb(52)gc(4)d(2)fe(14)f(6)g(8)h(4)5(6)";
  11. Pattern pattern = Pattern.compile("[a-g](?:\\(\\d+\\))?");
  12. List<String> res = new ArrayList<>();
  13. Matcher matcher = pattern.matcher(content);
  14. while (matcher.find()){
  15. res.add(matcher.group(0));
  16. }
  17. System.out.println(res);
  18. }
  19. }
Success #stdin #stdout 0.04s 2184192KB
stdin
Standard input is empty
stdout
[a, b, a(2), b, b(52), g, c(4), d(2), f, e(14), f(6), g(8)]