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 lordcheeto = @"\s*('.*?'|&&|==|<=|>=|<|>|\(|\)|\+|-|\|\|)\s*";
  11.  
  12. string input = "Name=='mynme' && CurrentTime<45 - 4";
  13. string input1 = "Name=='mynme' && CurrentTime<'2012-04-20 19:45:45'";
  14. string input2 = "((1==2) && 2-1==1) || 3+1==4 && Name=='Stefan+123'";
  15.  
  16. executePattern("lordcheeto's", input, lordcheeto);
  17. executePattern("lordcheeto's", input1, lordcheeto);
  18. executePattern("lordcheeto's", input2, lordcheeto);
  19.  
  20. Console.ReadLine();
  21. }
  22.  
  23. static void executePattern(string version, string input, string pattern)
  24. {
  25. // Avoiding repitition for this example.
  26. Console.WriteLine("Using {0} pattern:", version);
  27.  
  28. // Needs to be trimmed.
  29. var result = Regex.Split(input.Trim(), pattern);
  30.  
  31. // Pipe included to highlight empty strings.
  32. foreach (var m in result)
  33. Console.WriteLine("|{0}", m);
  34.  
  35. // Extra space.
  36. Console.WriteLine();
  37. Console.WriteLine();
  38. }
  39. }
  40. }
Success #stdin #stdout 0.08s 37360KB
stdin
Standard input is empty
stdout
Using lordcheeto's pattern:
|Name
|==
|
|'mynme'
|
|&&
|CurrentTime
|<
|45
|-
|4


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


Using lordcheeto's pattern:
|
|(
|
|(
|1
|==
|2
|)
|
|&&
|2
|-
|1
|==
|1
|)
|
|||
|3
|+
|1
|==
|4
|&&
|Name
|==
|
|'Stefan+123'
|