Hello _q12_,
your question is a bit ambiguous. Assuming that you have a predefined list of redundant entries, Regex does not help a lot. But nonetheless, the followong might help:
static void Main(string[] args)
{
List<string> redundant = new List<string>()
{
"abc",
"xyz",
"...",
};
string file = "datafileX.txt";
string data = File.ReadAllText(file);
data = ReplaceRedundantContent(data, redundant);
File.WriteAllText(file, data);
}
private static string ReplaceRedundantContent(string data, List<string> redundant)
{
string result = data;
foreach (string remove in redundant)
{
string pattern = Regex.Escape("<I>"+remove+"</I>");
result = Regex.Replace(result, pattern, "");
}
return result;
}
If you want to search for any text between the <I> and </I>, you may use the following pattern:
"<I>.*?</I>"
This matches all text by taking as little as possible, indicated by the question mark. If the question mark was not there, the match would be "greedy", meaning, that as much as possible is taken.
Cheers
Andi