I\'m new to regular expressions, and was wondering how I could get only the first number in a string like 100 2011-10-20 14:28:55. In this case, I\'d want it to
100 2011-10-20 14:28:55
public static void main(String []args){ Scanner s=new Scanner(System.in); String str=s.nextLine(); Pattern p=Pattern.compile("[0-9]+"); Matcher m=p.matcher(str); while(m.find()){ System.out.println(m.group()+" "); }