fork download
  1. using System;
  2. using System.Linq;
  3. using System.Text.RegularExpressions;
  4.  
  5. public class Test
  6. {
  7. public static void Main()
  8. {
  9. var delim = new string[] {"fox", "lazy"};
  10. var delimGroup = "(?:"+string.Join("|", delim.Select(Regex.Escape))+")";
  11. var pattern = @"\s(?="+delimGroup+")|(?<="+delimGroup+@")\s";
  12. var x = Regex.Split(
  13. "quick brown fox jumps over the lazy dog"
  14. , pattern
  15. );
  16. Console.WriteLine(pattern);
  17. foreach (var s in x)
  18. Console.WriteLine("[{0}]", s);
  19. }
  20. }
Success #stdin #stdout 0.06s 22168KB
stdin
Standard input is empty
stdout
\s(?=(?:fox|lazy))|(?<=(?:fox|lazy))\s
[quick brown]
[fox]
[jumps over the]
[lazy]
[dog]