YORDAN2347

RegexMatchPass

Apr 3rd, 2021
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.22 KB | None | 0 0
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. namespace P02
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             var pattern =
  11.                 @"([\W]+|[\w]+)>(?<digits>[0-9]{3})\|(?<lower>[a-z]{3})\|(?<upper>[A-Z]{3})\|(?<symbols>.[^<>]*)<\1";
  12.  
  13.             // problem with "<> at symbols group"
  14.  
  15.             var regex = new Regex(pattern);
  16.  
  17.             int n = int.Parse(Console.ReadLine());
  18.             for (int i = 0; i < n; i++)
  19.             {
  20.                 string input = Console.ReadLine();
  21.                 if (regex.IsMatch(input))
  22.                 {
  23.                     var match = regex.Match(input);
  24.                     string password = regex.Match(input).Groups["digits"].ToString();
  25.                     password += regex.Match(input).Groups["lower"].ToString();
  26.                     password += regex.Match(input).Groups["upper"].ToString();
  27.                     password += regex.Match(input).Groups["symbols"].ToString();
  28.                     Console.WriteLine($"Password: {password}");
  29.                 }
  30.                 else
  31.                 {
  32.                     Console.WriteLine($"Try another password!");
  33.                 }
  34.             }
  35.         }
  36.     }
  37. }
  38.  
Add Comment
Please, Sign In to add comment