fork(1) download
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. public class Test
  5. {
  6. public static void Main()
  7. {
  8. string s = "A B C C B C A D ABCD";
  9.  
  10. foreach (Match m in Regex.Matches(s, @"\b(\w+)\b(?=.*\b\1\b)(?!.*\b\1\b.*\b\1\b)(?<!\b\1\b.+)", RegexOptions.IgnoreCase))
  11. Console.WriteLine(m.Value);
  12. }
  13. }
Success #stdin #stdout 0.06s 21364KB
stdin
Standard input is empty
stdout
A
B