title: How do I search and replace text containing placeholder tokens with a values from an xml file using regular expression matching. VB.net or C#
body: <p>I have a problem that requires vb.net or C# solution with regular expressions matching.
  I am not very good with regular expressions and so I thought I would ask for some help.
  I have some text that has one or more tokens that I need to replace with values retrieved from an xml file. Tokens are similar but are of 2 different types. For matches of the first type I will replace with a value from file1.xml and for matches of the 2nd type from file2.xml.</p>
  
  <p>The replaceable tokens are in this format:</p>
  
  <p>Type 1 Tokens: <strong>&amp;*T1&amp;</strong> and <strong>&amp;*T1001&amp;</strong></p>
  
  <p>Type 2 Tokens: <strong>&amp;*SomeValue&amp;</strong> and <strong>&amp;*A2ndValue&amp;</strong></p>
  
  <p>The replacement values for the Type 1 tokens are in File1.xml and for Type 2 Tokens are in File2.xml</p>
  
  <p>In the above example, when a match is found for Type 1 (T1000), I need to replace the entire token (&amp;*T1000&amp;) with the value of Element T1000 in File1.xml. <code>&lt;T1000&gt;ValueT1000&lt;/T1000&gt;</code></p>
  
  <p>In the 2nd Type: When a match is found for Type 2 (SomeValue), I need to replace the entire token (&amp;*SomeValue&amp;) with the value of Element SomeValue in File2.xml. <code>&lt;SomeValue&gt;Value2&lt;/SomeValue&gt;</code></p>
  
  <p>Example input text:
  <strong>This is some text with first token <code>&amp;T1&amp;</code> and the second token <code>&amp;*T1001&amp;</code> and more tokens <code>&amp;*SomeValue&amp;</code> and still more <code>&amp;*A2ndValue&amp;</code>.</strong></p>
  
  <p>So far with help of the code from pirs, in vb.net, I have this:</p>
  
  <pre><code>Public Shared Sub Main()
      Dim pattern As String = "\&amp;\*?([\w]+)\&amp;"
      Dim input As String = "This is some text with first token &amp;*T1&amp; and the second token &amp;*T1001&amp; and more tokens &amp;*SomeValue&amp; and still more &amp;*A2ndValue&amp;."
          For Each m As Match In Regex.Matches(input, pattern)
              Console.WriteLine("'{0}' found at index {1}.", m.Groups(1).Value, m.Index)
          Next
  End Sub
  </code></pre>
  
  <p>Which returns:</p>
  
  <pre><code>'T1' found at index 35.
  'T1001' found at index 62.
  'SomeValue' found at index 87.
  'A2ndValue' found at index 115
  </code></pre>
  
  <p>I need to process this text and replace all the tokens with their values retrieved from the 2 xml files. 
  Any help is appreciated.</p>
  
  <p><strong>[EDIT]</strong><br>
  With answer from @pirs. Maybe the way to do it is to first find matches of type T1000 and then replace by regex index of match. When replacing by index, I think I have to start at last index since each replace will change the index of matches.<br>
  After all T1000 matches are replaced I think I can do another match on the output string from the above and then replace all the matches of 2nd type.</p>
  
  <p>What is regex match for T1000 (T followed by any number of digits)</p>