fork 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 s = "Dsfgdsf ghdsgtaq sadf 5hs a sdgewrg.1) AF AFDS (1,1-3). sdfwurf sgwefasöpopwe,4) qdasda (2,3-29). jkgwgvsd sdfawefas2)";
  11. Pattern pattern = Pattern.compile("\\(\\d[\\d,-]*\\)|(\\d+\\))");
  12. Matcher matcher = pattern.matcher(s);
  13. while (matcher.find()){
  14. if (matcher.group(1) != null) {
  15. System.out.println(matcher.group(1));
  16. }
  17. }
  18. }
  19. }
Success #stdin #stdout 0.04s 4386816KB
stdin
Standard input is empty
stdout
1)
4)
2)