fork(2) download
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. public class Test
  5. {
  6. public static void Main()
  7. {
  8. string input = "Foo! The quick brown fox. Bar! ";
  9. input = input + input + input + input; // repeated, each string takes about ~100ms
  10. string pattern = @"([a-z ]+)+!";
  11. var matchTimeout = TimeSpan.FromMilliseconds(150); // Decrease to ~100 to timeout
  12. try
  13. {
  14. var result = Regex.Replace(input, pattern, "X",
  15. RegexOptions.None,
  16. matchTimeout);
  17. Console.WriteLine("Result: " + result);
  18. }
  19. catch (RegexMatchTimeoutException ex)
  20. {
  21. Console.WriteLine("Match timed out!");
  22. Console.WriteLine("- Timeout interval specified: " + ex.MatchTimeout);
  23. Console.WriteLine("- Pattern: " + ex.Pattern);
  24. Console.WriteLine("- Input: " + ex.Input);
  25. }
  26. }
  27. }
Success #stdin #stdout 0.48s 133824KB
stdin
Standard input is empty
stdout
Result: FX The quick brown fox. BX FX The quick brown fox. BX FX The quick brown fox. BX FX The quick brown fox. BX