fork download
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. namespace RegEx
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. string original = "([+\\-*/%()]{1}|[=<>!]{1,2}|[&|]{2})";
  11. string lordcheeto = @"\s*(==|&&|<=|>=|<|>)\s*";
  12.  
  13. string input = "Name=='mynme' && CurrentTime<45 - 4";
  14. string input1 = "Name=='mynme' && CurrentTime<'2012-04-20 19:45:45'";
  15. string ridiculous = "Name == BLAH && !@#>=$%^&*()< ASDF && this > that";
  16.  
  17. executePattern("original", input, original);
  18. executePattern("lordcheeto's", input, lordcheeto);
  19. executePattern("original", input1, original);
  20. executePattern("lordcheeto's", input1, lordcheeto);
  21. executePattern("original", ridiculous, original);
  22. executePattern("lordcheeto's", ridiculous, lordcheeto);
  23. }
  24.  
  25. static void executePattern(string version, string input, string pattern)
  26. {
  27. // Avoiding repitition for this example.
  28. Console.WriteLine("Using {0} pattern:", version);
  29.  
  30. // Needs to be trimmed.
  31. var result = Regex.Split(input.Trim(), pattern);
  32.  
  33. // Pipes included to highlight whitespace trimming.
  34. foreach (var m in result)
  35. Console.WriteLine("|{0}|", m);
  36.  
  37. // Extra space.
  38. Console.WriteLine();
  39. Console.WriteLine();
  40. }
  41. }
  42. }
Success #stdin #stdout 0.07s 38488KB
stdin
Standard input is empty
stdout
Using original pattern:
|Name|
|==|
|'mynme' |
|&&|
| CurrentTime|
|<|
|45 |
|-|
| 4|


Using lordcheeto's pattern:
|Name|
|==|
|'mynme'|
|&&|
|CurrentTime|
|<|
|45 - 4|


Using original pattern:
|Name|
|==|
|'mynme' |
|&&|
| CurrentTime|
|<|
|'2012|
|-|
|04|
|-|
|20 19:45:45'|


Using lordcheeto's pattern:
|Name|
|==|
|'mynme'|
|&&|
|CurrentTime|
|<|
|'2012-04-20 19:45:45'|


Using original pattern:
|Name |
|==|
| BLAH |
|&&|
| |
|!|
|@#|
|>=|
|$|
|%|
|^&|
|*|
||
|(|
||
|)|
||
|<|
| ASDF |
|&&|
|    this          |
|>|
|          that|


Using lordcheeto's pattern:
|Name|
|==|
|BLAH|
|&&|
|!@#|
|>=|
|$%^&*()|
|<|
|ASDF|
|&&|
|this|
|>|
|that|