Advertisement
deyanmalinov

08. Match Dates

Mar 23rd, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.78 KB | None | 0 0
  1. package DPM;
  2.  
  3. import java.util.Scanner;
  4. import java.util.regex.Matcher;
  5. import java.util.regex.Pattern;
  6.  
  7. public class Main {
  8.         public static void main(String[] args) {
  9.             Scanner scan = new Scanner(System.in);
  10.             String string = scan.nextLine();
  11.             String regex = "\\b(?<buk>\\d{2})([-.\\/])(?<cif>[A-Z][a-z]{2})\\2(?<nish>[\\d]{4})\\b";
  12.             Pattern pattern = Pattern.compile(regex);
  13.             Matcher line = pattern.matcher(string);
  14.  
  15.  
  16.             while (line.find()) {
  17.                 String buk = line.group("buk");
  18.                 String cif = line.group("cif");
  19.                 String nish = line.group("nish");
  20.                System.out.printf("Day: %s, Month: %s, Year: %s\n", buk, cif, nish);
  21.             }
  22.  
  23.  
  24.         }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement