fork download
  1. import java.util.*;
  2. import java.util.regex.*;
  3. import java.lang.*;
  4. import java.io.*;
  5.  
  6. class Ideone
  7. {
  8. public static void main (String[] args) throws java.lang.Exception
  9. {
  10. final String REGEX = "(.*?)(\\d{1,2})([-./])(\\d{1,2})(.*)";
  11. String dayAndMonth = "This year 12.03 i visited Italy";
  12. Pattern pattern = Pattern.compile(REGEX);
  13. Matcher matcher = pattern.matcher(dayAndMonth);
  14. if (matcher.matches()){
  15. String day = matcher.group(2);
  16. String month = matcher.group(4);
  17. System.out.println(day+" "+month);
  18. }
  19. }
  20. }
Success #stdin #stdout 0.09s 27824KB
stdin
Standard input is empty
stdout
12 03