valiamaximova1

Regex java

Apr 3rd, 2021 (edited)
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.95 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.regex.Matcher;
  3. import java.util.regex.Pattern;
  4.  
  5. public class first {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.         int n = Integer.parseInt(scanner.nextLine());
  9.  
  10.         String productRegex = "([\\W\\w]+)>(?<numbers>\\d{3})\\|(?<smallWords>[a-z]{3})\\|(?<bigWords>[A-Z]{3})\\|(?<symbols>[^><]{3})<\\1";
  11.         Pattern pattern = Pattern.compile(productRegex);
  12.  
  13.  
  14.         for (int i = 0; i < n; i++) {
  15.             String password = scanner.nextLine();
  16.             Matcher matcher = pattern.matcher(password);
  17.  
  18.             if(matcher.find()){
  19.                 System.out.printf("Password: %s%n", matcher.group("numbers") +
  20.                         matcher.group("smallWords")+ matcher.group("bigWords") + matcher.group("symbols"));
  21.  
  22.             }else{
  23.                 System.out.println("Try another password!");
  24.             }
  25.  
  26.         }
  27.     }
  28. }
  29.  
Add Comment
Please, Sign In to add comment