fork download
  1. using System;
  2. using System.Text.RegularExpressions;
  3. using System.Collections.Specialized;
  4. class Program
  5. {
  6. static void Main() {
  7. var myRegex = new Regex(@"IgnoreFunction\s*(['""])[^']*\1|AlsoIgnoreFunction\[[^\]]*\]|(ANDALSO|ORELSE)");
  8. string s1 = @"SomeVar ANDALSO SomeOTherVar ANDALSO AnotherVar = 1234 IgnoreFunction 'SomeVar=ANDALSO AnotherVar'
  9. AlsoIgnoreFunction['test=value', 'anotherTest = ANDALSO anotherValue'] ORELSE ANDALSO";
  10.  
  11. string replaced = myRegex.Replace(s1, delegate(Match m) {
  12. if (m.Groups[2].Value == "ANDALSO") return "&&";
  13. else if (m.Groups[2].Value == "ORELSE") return "||";
  14. else return m.Value;
  15. });
  16. Console.WriteLine("\n" + "*** Replacements ***");
  17. Console.WriteLine(replaced);
  18.  
  19.  
  20. Console.WriteLine("\nPress Any Key to Exit.");
  21. Console.ReadKey();
  22.  
  23. } // END Main
  24. } // END Program
Success #stdin #stdout 0.07s 34200KB
stdin
Standard input is empty
stdout
*** Replacements ***
SomeVar && SomeOTherVar && AnotherVar = 1234 IgnoreFunction 'SomeVar=ANDALSO AnotherVar'
AlsoIgnoreFunction['test=value', 'anotherTest = ANDALSO anotherValue'] || &&

Press Any Key to Exit.