Replace multiple Regex Matches each with a different replacement
<p>I have a string that may or may not have multiple matches for a designated pattern.</p>

<p>Each needs to be replaced.</p>

<p>I have this code:</p>

<pre><code>var pattern = @"\$\$\@[a-zA-Z0-9_]*\b";
var stringVariableMatches = Regex.Matches(strValue, pattern);
var sb = new StringBuilder(strValue);

foreach (Match stringVarMatch in stringVariableMatches)
{
    var stringReplacment = variablesDictionary[stringVarMatch.Value];
    sb.Remove(stringVarMatch.Index, stringVarMatch.Length)
            .Insert(stringVarMatch.Index, stringReplacment);
}

return sb.ToString();
</code></pre>

<p>The problem is that when I have several matches the first is replaced and the starting index of the other is changed so that in some cases after the replacement when the string is shorten I get an index out of bounds..</p>

<p>I know I could just use <code>Regex.Replace</code> for each match but this sound performance heavy and wanted to see if someone could point a different solution to substitute multiple matches each with a different string.</p>