SHARE
TWEET

Untitled

a guest Nov 21st, 2019 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2. import java.util.regex.Matcher;
  3. import java.util.regex.Pattern;
  4.  
  5. public class regExMatchdates {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         String imput = scanner.nextLine();
  10.         String regex = "(?<Day>\\d{2})([./-])(?<Month>[A-Z][a-z]+)(\\2)(?<Year>\\d{4})";
  11.  
  12.         Pattern pattern = Pattern.compile(regex);
  13.         Matcher matcher = pattern.matcher(imput);
  14.  
  15.         while (matcher.find()){
  16.             String day = matcher.group("Day");
  17.             String month = matcher.group("Month");
  18.             String year = matcher.group("Year");
  19.  
  20.             System.out.printf("Day: %s, Month: %s, Year: %s%n",day,month,year);
  21.         }
  22.     }
  23. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top