String aa = "asd5sdasd54"; Pattern p = Pattern.compile("\\d+"); Matcher m=p.matcher(aa); if(m.find()){ System.out.println(m.group()); }