fork(1) 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 strs = new List<string> { "a d e ads", "H e l l o Everyone", "a b c def", "a b c def", "Hello world", "a ads", "a d ads" };
  12. foreach (var s in strs)
  13. {
  14. var res = Regex.Replace(s, @"(?<!\S)\w(?:\s\w){2,}(?!\S)", m =>
  15. new string(m.Value
  16. .Where(c => !Char.IsWhiteSpace(c))
  17. .ToArray()));
  18. Console.WriteLine(res);
  19. }
  20. }
  21. }
Success #stdin #stdout 0.03s 30688KB
stdin
Standard input is empty
stdout
ade ads
Hello Everyone
abc def
abc  def
Hello world
a ads
a d ads