fork download
  1. using System;
  2. using System.Linq;
  3. using System.IO;
  4. using System.Text.RegularExpressions;
  5.  
  6. public class Test
  7. {
  8. public static void Main()
  9. {
  10. var keep = "[^\"\\\\]*(?:\\\\.[^\"\\\\]*)*";
  11. var rx = string.Format("^(?:(?<keep>{0})\"{0}\")+(?<keep>{0})$", keep);
  12. var s = @"Test + ""Hello"" + ""Good\""more"" + \""Escape\""This\""Test\"" + ""f""";
  13. var matches = Regex.Matches(s, rx)
  14. .Cast<Match>()
  15. .SelectMany(m => m.Groups["keep"].Captures.Cast<Capture>().Select(p => p.Value).ToArray())
  16. .ToList();
  17. Console.WriteLine(string.Join("", matches));
  18.  
  19. }
  20. }
Success #stdin #stdout 0.12s 24720KB
stdin
Standard input is empty
stdout
Test +  +  + \"Escape\"This\"Test\" +