fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5.  
  6. public class Test
  7. {
  8. public static void Main()
  9. {
  10. var sentence = "I was watching TV last night while she was reading a book and you were playing video games";
  11. var result = Regex.Replace(sentence, @"\b(?:(I was)|you were)\b", m =>
  12. m.Groups[1].Success ? "you were" : "I was");
  13. Console.WriteLine(result);
  14. }
  15. }
Success #stdin #stdout 0.07s 21080KB
stdin
Standard input is empty
stdout
you were watching TV last night while she was reading a book and I was playing video games