I will skip the discussion of “don't parse HTML with regex” and suppose you're looking at the overloads for Regex.Replace that accept the MatchEvaluator delegate.
Basically, you can pass a delegate to the Replace () method, which is called for each match and returns the replacement text.
This MSDN page provides an example of entering an index number in replacement text. You should be able to use the index in your array to get the replacement text.
Here is a sample reflecting your example:
string[] middleXMLTags = {"</Table1><Table2>", "</Table2><Table3>"}; string response = "</Table><Table><foo/></Table><Table>"; Console.WriteLine(response); int i = 0; response = Regex.Replace(response,@"</Table><Table>",m=>middleXMLTags[i++]); Console.WriteLine(response);
Output:
</Table><Table><foo/></Table><Table> </Table1><Table2><foo/></Table2><Table3>
source share