Advertisement
daxtera

Untitled

Mar 25th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. using System;
  2. using System.Text.RegularExpressions;
  3. namespace Regex_More_Exercise
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. int numberOfMessages = int.Parse(Console.ReadLine());
  10.  
  11. string namePattern = @"(?<=@)([A-z]+)\|";
  12. Regex nameRegex = new Regex(namePattern);
  13.  
  14. string yearsPattern = @"(?<=#)([0-9]+)\*";
  15. Regex yearsRegex = new Regex(yearsPattern);
  16.  
  17. for (int i = 0; i < numberOfMessages; i++)
  18. {
  19. string message = Console.ReadLine();
  20.  
  21. Match nameMatch = nameRegex.Match(message);
  22. Match yearsMatch = yearsRegex.Match(message);
  23.  
  24. if (nameMatch.Success&& yearsMatch.Success)
  25. {
  26. Console.WriteLine($"{nameMatch.Groups[1].Value} is {yearsMatch.Groups[1].Value} years old.");
  27. }
  28.  
  29. }
  30. }
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement