public static void date(String s){ Pattern p =Pattern.compile("\\d{1,2}+.\\d{1,2}+.\\d{4}+"); Matcher m = p.matcher(s); while (m.find()){ System.out.println(m.group()); } } There is such a method, it finds the date of birth in the text, but I need to make a condition on which you can set the first value from 1-31 to the second condition 1-12. In my example, if I specify 341 in the first value, then it will only display 41