Advertisement
PIBogdanov

02. Registration

Dec 11th, 2023
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.01 KB | None | 0 0
  1. using System.Text.RegularExpressions;
  2.  
  3. namespace _02.Registration;
  4.  
  5. internal class Program
  6. {
  7.     static void Main(string[] args)
  8.     {
  9.         string pattern = @"^[U][$](?<username>[A-Z][a-z]{2,})[U][$].*?[P][@][$](?<password>[A-Za-z]{5,}[A-Za-z0-9]*?\d)[P][@][$]$";
  10.  
  11.         short inputCount = short.Parse(Console.ReadLine());
  12.  
  13.         int validRegexCount = 0;
  14.  
  15.         for (int i = 0; i < inputCount; i++)
  16.         {
  17.             string regexInput = Console.ReadLine();
  18.  
  19.             Match match = Regex.Match(regexInput, pattern);
  20.  
  21.             if (match.Success)
  22.             {
  23.                 Console.WriteLine($"Registration was successful");
  24.  
  25.                 Console.WriteLine($"Username: {match.Groups["username"].Value}, Password: {match.Groups["password"].Value}");
  26.  
  27.                 validRegexCount++;
  28.  
  29.                 continue;
  30.             }
  31.  
  32.             Console.WriteLine($"Invalid username or password");
  33.         }
  34.  
  35.         Console.Write($"Successful registrations: {validRegexCount}");
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement