using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
public class Test
{
public static void Main()
{
var sentence = "I was watching TV last night while she was reading a book and you were playing video games";
var result = Regex.Replace(sentence, @"\b(?:(I was)|you were)\b", m =>
m.Groups[1].Success ? "you were" : "I was");
Console.WriteLine(result);
}
}
dXNpbmcgU3lzdGVtOwp1c2luZyBTeXN0ZW0uQ29sbGVjdGlvbnMuR2VuZXJpYzsKdXNpbmcgU3lzdGVtLkxpbnE7CnVzaW5nIFN5c3RlbS5UZXh0LlJlZ3VsYXJFeHByZXNzaW9uczsKCnB1YmxpYyBjbGFzcyBUZXN0CnsKCXB1YmxpYyBzdGF0aWMgdm9pZCBNYWluKCkKCXsKCQl2YXIgc2VudGVuY2UgPSAiSSB3YXMgd2F0Y2hpbmcgVFYgbGFzdCBuaWdodCB3aGlsZSBzaGUgd2FzIHJlYWRpbmcgYSBib29rIGFuZCB5b3Ugd2VyZSBwbGF5aW5nIHZpZGVvIGdhbWVzIjsKCQl2YXIgcmVzdWx0ID0gUmVnZXguUmVwbGFjZShzZW50ZW5jZSwgQCJcYig/OihJIHdhcyl8eW91IHdlcmUpXGIiLCBtID0+CgkJCW0uR3JvdXBzWzFdLlN1Y2Nlc3MgPyAieW91IHdlcmUiIDogIkkgd2FzIik7CiAgICAgICAgQ29uc29sZS5Xcml0ZUxpbmUocmVzdWx0KTsKCX0KfQ==