Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- using System.Text;
- using System.Text.RegularExpressions;
- namespace _02_Registration
- {
- class Program
- {
- static void Main(string[] args)
- {
- string pattern = @"^[U][$](?<username>[A-Z][a-z]{2,})[U][$].*?[P][@][$](?<password>[A-Za-z]{5,}[A-Za-z0-9]*?\d)[P][@][$]$";
- int n = int.Parse(Console.ReadLine());
- int validRegCount = 0;
- for (int i = 0; i < n; i++)
- {
- string regInput = Console.ReadLine();
- Match match = Regex.Match(regInput, pattern);
- if (match.Success)
- {
- Console.WriteLine($"Registration was successful");
- Console.WriteLine($"Username: {match.Groups["username"].Value}, Password: {match.Groups["password"].Value}");
- validRegCount++;
- }
- else
- {
- Console.WriteLine($"Invalid username or password");
- }
- }
- Console.WriteLine($"Successful registrations: {validRegCount}");
- }
- }
- }
Add Comment
Please, Sign In to add comment