fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text.RegularExpressions;
  6.  
  7. public class Test
  8. {
  9. public static void Main()
  10. {
  11. var text = @"iPhone 6S Plus
  12. iPhone SE
  13. iPhone 7
  14. iPhone 8 Plus
  15. iPhone X
  16. iPhone XS
  17. iPhone 11 Pro Max
  18. iPhone 12 Mini
  19. iPhone 13 Pro Max
  20. iPhone SE
  21. iPhone SE2
  22. iPhone SE3
  23. iPhone SE (1st Generation)
  24. iPhone SE (2nd Generation)
  25. iPhone SE (3rd Generation)";
  26. var pattern = @"iPhone\s*(?:(?<p>X|\d+)|(?<p>SE)(?:[^\d\n]*(?<n>\d+))?)";
  27. var result = Regex.Matches(text, pattern)
  28. .Cast<Match>()
  29. .Select(m => $"{m.Groups["p"].Value}{m.Groups["n"].Value}")
  30. .ToList();
  31. foreach (var s in result)
  32. Console.WriteLine(s);
  33. }
  34. }
Success #stdin #stdout 0.1s 30092KB
stdin
Standard input is empty
stdout
6
SE
7
8
X
X
11
12
13
SE
SE2
SE3
SE1
SE2
SE3