fork(2) download
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. public class Test
  5. {
  6. public static void Main()
  7. {
  8. string input = "blablablabla12345b\nMain Storage : C61\nC62 : 1215\nC61 : 1785\nblablablabla12345blablablabla";
  9.  
  10. string pattern = @"(?: : (?<portion>[A-Z]{1,2}[0-9]{2})|^\s*(?<portion>[A-Z]{1,2}[0-9]{2}) :)(?!.*(?: : \k<portion>|^\s*\k<portion> :))";
  11. MatchCollection matches = Regex.Matches(input, pattern, RegexOptions.Singleline | RegexOptions.Multiline);
  12.  
  13. foreach (Match match in matches)
  14. {
  15. GroupCollection groups = match.Groups;
  16. Console.WriteLine( groups["portion"].Value );
  17. }
  18. }
  19. }
Success #stdin #stdout 0.11s 24712KB
stdin
Standard input is empty
stdout
C62
C61