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 texts = new List<string> { "Na#me","M2a_ny","Vari{sq}o@us","test [sq]uirrel h23ere!" };
  12. var pattern = @"((?:(?!{sq})[A-Za-z0-9\s])+)|{sq}";
  13. foreach (var text in texts) {
  14. var result = Regex.Matches(text, pattern).Cast<Match>()
  15. .Aggregate("", (s, e) => s + e.Groups[1].Value, s => s);
  16. Console.WriteLine(result);
  17. }
  18. }
  19. }
Success #stdin #stdout 0.06s 30824KB
stdin
Standard input is empty
stdout
Name
M2any
Various
test squirrel h23ere