title: Extract groups with regex and construct URL in a single line
body: <p>I am currently trying to extract values from a string and construct a URL that includes those values. I went through a dozen regex question, but I am not quite satisfied with the answers.</p>
  
  <p>I have custom encoded strings with more than one information and I want to construct a new URL that contains those information.</p>
  
  <p>For example <code>35afe06d-8393-4559-b6d7-74d35ce131d8|Master</code> should become <code>http://my-server/media/guid/35afe06d-8393-4559-b6d7-74d35ce131d8?v=Master</code>. My first assumption was </p>
  
  <pre class="lang-cs prettyprint-override"><code>var input = "35afe06d-8393-4559-b6d7-74d35ce131d8|Master"
  var pattern = @"((?:[a-f0-9]+-?){5})|(\w+)"
  var replacement = "http://my-server/media/guid/$1?v=$2"
  var output = Regex.Replace(input, pattern, replacement)
  </code></pre>
  
  <p>However this replaces each group with the full URL. Limitation is, that I am not aware of <code>input</code>, <code>pattern</code>, <code>replacement</code> or <code>output</code>. <code>pattern</code> and <code>replacement</code> are two config values and I don't want to make it x pairs of config values, <code>input</code> comes from somewhere else in the application and could have any custom encoding (pipe, colon, ...) <code>output</code> depends on the use case. It can have any number of groups in the pattern and doesn't even have to be a URL in the end.</p>
  
  <p>I can think of different ways to do this, like parsing the string myself, or trying to create a replacement dictionary, or using regex to find the groups and then string replace for <code>$1</code> => match.Groups[0]. I just feel like there must be an obvious 1-liner solution for that in .NET since I even remember doing that in PHP.</p>
  
  <p><strong>Answer</strong>: It's not a .NET limitation, it was simply the unescaped pipe. </p>