fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.util.regex.*;
  7.  
  8. /* Name of the class has to be "Main" only if the class is public. */
  9. class Ideone
  10. {
  11. public static void main (String[] args) throws java.lang.Exception
  12. {
  13. String str = "The problem is that it correctly gives a match for 5,6,7,8 etc but not for 17 or 251 for example. 0,1,2,3,4,9,11,12,13,14,15,16,18,19,250";
  14. Pattern p = Pattern.compile("\\b(?:[0-49]|1[1-689]|250)\\b|(\\d+)");
  15. Matcher m = p.matcher(str);
  16.  
  17. while (m.find() && m.group(1) != null) {
  18. System.out.print(m.group(1) + " ");
  19. }
  20. }
  21. }
Success #stdin #stdout 0.05s 4386816KB
stdin
Standard input is empty
stdout
5 6 7 8 17 251