title: How to Regex replace match group item with method result
body: <p>The input string is something like this:</p>
  
  <p>LineA: 50</p>
  
  <p>LineB: 120</p>
  
  <p>LineA: 12</p>
  
  <p>LineB: 53</p>
  
  <p>I would like to replace the LineB values with a result of <code>MultiplyCalculatorMethod(LineAValue)</code>, where <code>LineAValue</code> is the value of the line above <code>LineB</code> and <code>MultiplyCalculatorMethod</code> is my other, complicated C# method.</p>
  
  <p>In semi-code, I would like to do something like this:</p>
  
  <pre><code>int MultiplyCalculatorMethod(int value)
  {
     return 2 * Math.Max(3,value);
  }
  string ReplaceValues(string Input)
  {
     Matches mat = Regex.Match(LineA:input_value\r\nLineB:output_value)
     foreach (Match m in mat)
     {
         m.output_value = MultiplyCalculatorMethod(m.input_value)
     }
     return m.OutputText;
  }
  
  Example:
  
  string Text = "LineA:5\r\nLineB:2\r\nLineA:2\r\nLineB:7";
  string Result = ReplaceValues(Text);
  //Result = "LineA:5\r\nLineB:10\r\nLineA:2\r\nLineB:6";
  </code></pre>
  
  <p>I wrote a <code>Regex.Match</code> to match <code>LineA: value\r\nLineB: value</code> and get these values in groups. But when I use <code>Regex.Replace</code>, I can only provide a "static" result that is combining groups from the match, but I can not use C# methods there.</p>
  
  <p>So my questions is how to Regex.Replace where Result is a result of C# method where input is LineA value.</p>