fork(2) download
  1. using System;
  2. using System.IO;
  3. using System.Text.RegularExpressions;
  4.  
  5. public class Test
  6. {
  7. public static void Main()
  8. {
  9. var s = "'This is not captured' but this is and not or empty() notempty() currentdate() capture";
  10. var rx = new Regex(@"(?:'[^']*'|(?:\b(?:(?:not)?empty|currentdate)\(\)|and|or|not))|([!@#$%^&*_.\w-]+)");
  11. Console.WriteLine(rx.Replace(s, repl));
  12. }
  13. public static string repl(Match m)
  14. {
  15. return !string.IsNullOrEmpty(m.Groups[1].Value) ? m.Value.Replace(m.Groups[1].Value, string.Format("'{0}'", m.Groups[1].Value)) : m.Value;
  16. }
  17. }
Success #stdin #stdout 0.09s 24600KB
stdin
Standard input is empty
stdout
'This is not captured' 'but' 'this' 'is' and not or empty() notempty() currentdate() 'capture'