/* package whatever; // don't place package name! */
importjava.util.*;
importjava.lang.*;
importjava.io.*;
importjava.util.regex.*;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
publicstaticvoid main (String[] args)throws java.lang.Exception
{
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";
Pattern p = Pattern.compile("\\b(?:[0-49]|1[1-689]|250)\\b|(\\d+)");