title: Regex replace string function not working as expected
body: <p>I'm trying to implement a hashtag function in a web app to easily embed search links into a page. The issue is that I'm trying to do a replace on the hash marks so they don't appear in the HTML output. Since I'm also wanting to be able to also have hash marks in the output I can't just do a final <code>Replace</code> on the entire string at the end of processing. I'm going to want to be able to escape some hash marks like so <code>\#1 is my answer</code> and I'd find and replace the <code>\#</code> with just <code>#</code> but that is another problem that I'm not even ready for (but still thinking of). </p>
  
  <p>This is what I have so far mocked up in a console app, </p>
  
  <pre><code>static void Main(string[] args)
  {
      Regex _regex = new Regex(@"(#([a-z0-9]+))");
      string link = _regex.Replace("&lt;p&gt;this is #my hash #tag.&lt;/p&gt;", MakeLink("$1"));
  }
  public static string MakeLink(string tag)
  {
      return string.Format("&lt;a href=\"/Search?t={0}\"&gt;{1}&lt;/a&gt;", tag.Replace("#", ""), tag);
  }
  </code></pre>
  
  <p>The output being:<br>
  <code>&lt;p&gt;this is &lt;a href="/Search?t=#my"&gt;#my&lt;/a&gt; hash &lt;a href="/Search?t=#tag"&gt;#tag&lt;/a&gt;.&lt;/p&gt;</code></p>
  
  <p>But when I run it with breaks while it's running <code>MakeLink()</code> it's string is displayed at <code>"$1"</code> in the debugger output and it's not replacing the hash's as expected. </p>
  
  <p>Is there a better tool for the job than regex? Or can I do something else to get this working correctly? </p>