I expect there would some others ways to do this, but i came up with the following approach that uses named groups and anonymous methods.
I have assumed in my example that 123, 456, 789 will be replaced with 111, 444, 777 respectively while 000 will remain intact in the string.
I have used an approach to name the group a value that will be a use as a replacement value. For example here in this part:
(?<111>123) = value 123 will be replace by 111 where 111 is also the name of the group.
So, a general pattern would become: (?<ValueToReplace>ValueToSearch)
Here is a sample code:
Dim sampleText = "123 456 789 000"
Dim re As New Regex("\b(?<111>123)\b|\b(?<444>456)\b|\b(?<777>789)\b")
Dim count As Integer = re.Matches(sampleText).Count
Dim contents As String = re.Replace(sampleText, New MatchEvaluator(Function(c) re.GetGroupNames().Skip(1).ToArray().GetValue(c.Captures(0).Index Mod count).ToString()))
From your approach I expect you work in VB.Net but i have attached a C# version too.
Here, is the C# version:
var sampleText = @"123 456 789 000";
Regex re = new Regex(@"\b(?<111>123)\b|\b(?<444>456)\b|\b(?<777>789)\b");
int count = re.Matches(sampleText).Count;
string contents = re.Replace(sampleText, new MatchEvaluator((c) => re.GetGroupNames().Skip(1).ToArray().GetValue(c.Captures[0].Index % count).ToString()));
replacePatternthat does different things depending on the input?