fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4. import java.util.regex.Matcher;
  5. import java.util.regex.Pattern;
  6.  
  7.  
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. final String regex = "(?:\\w+|\\G(?!^))\\h*,\\h*([0-9]+)";
  13. final String string = "sdfs6df -> no capture\n\n"
  14. + "fdg4dfg, 5 -> capture 5\n\n"
  15. + "fhhh3 , 6,8 , 7 -> capture 6 8 and 7\n\n"
  16. + "asdasd1,4,2,7 -> capture 4 2 and 7";
  17.  
  18. final Pattern pattern = Pattern.compile(regex);
  19. final Matcher matcher = pattern.matcher(string);
  20.  
  21. while (matcher.find()) {
  22. System.out.println(matcher.group(1));
  23. }
  24. }
  25. }
Success #stdin #stdout 0.09s 34060KB
stdin
Standard input is empty
stdout
5
6
8
7
4
2
7