fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text.RegularExpressions;
  6.  
  7. public class Test
  8. {
  9. public static void Main()
  10. {
  11. var exceptions = new[] { "and", "not", "or" };
  12. Console.WriteLine($@"\b(?!(?:{string.Join("|", exceptions)})\b)\w+");
  13. var result = Regex.Replace("This and This not That",
  14. $@"\b(?!({string.Join("|", exceptions)})\b)\w+",
  15. "\"$&\"");
  16. Console.WriteLine(result);
  17. }
  18. }
Success #stdin #stdout 0.05s 21340KB
stdin
Standard input is empty
stdout
\b(?!(?:and|not|or)\b)\w+
"This" and "This" not "That"