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

    1 answer 1

    If I understand you correctly, then you need a monster like this:

     (0[1-9]|[12][0-9]|3[0-1])(0[1-9]|1[0-2]) 

    The first group is day 01-31, the second group is month 01-12

    • Can you explain how it works? - Vlad Kesia
    • one
      2 groups: The first is looking for the number, and the second month. Used operator | or. Each is aimed at a specific numeric version. For example, if we have a number up to 10, then the first number will be 0, and the second number starts from 1 to 9. - iluxa1810
    • If we need the number 20, then we need to set from 0 to 9 several times - Vlad Kesya
    • one
      If you need an exact match, find 20, then [2] [0]. On the wiki, a good tutorial is ru.wikipedia.org/wiki/… - iluxa1810