title: Iterating over a list in a regular expression replacement
body: <p>I have a string with a prefix followed by list of at least one possibly empty suffix. The suffixes themselves are prefixed with a colon. Neither prefix nor suffix must contain any colon.</p>
  
  <p>Example (1) for one empty suffix:</p>
  
  <pre><code>x:
  </code></pre>
  
  <p>Example (2) for two non empty suffixes ("a" and "b") and one empty suffix:</p>
  
  <pre><code>x:a::b
  </code></pre>
  
  <p>The <a href="http://regexpal.com/?flags=g&amp;regex=%28%5B%5E%3a%5D%2b%29%28%3a%28%5B%5E%3a%5D%2a%29%29%2a&amp;input=x%3aa%3a%3ab" rel="nofollow">regular expression</a> for this pattern is:</p>
  
  <pre><code>([^:]+)(:([^:]*))*
  </code></pre>
  
  <p>The first match captures the prefix and the (3+2n)th match captures the suffixes (n = [0,1,2,...]).</p>
  
  <p>In my replacement I would like to prefix each suffix. Example (1) should produce:</p>
  
  <pre><code>x
  </code></pre>
  
  <p>And example (2) should produce:</p>
  
  <pre><code>xa
  x
  xb
  </code></pre>
  
  <p>How do I have to specify the replacement expression?</p>
  
  <p>My problem is, that the first replacement eats the prefix. And after that the second replacement does not see the prefix any more. I have to preserve the prefix for the remaining replacements. How can this be done?</p>