title: Unable to get captured group value
body: <p>This is how my Input looks like:</p>
  
  <pre><code>"A1-BC-12345-D2"
  </code></pre>
  
  <p>This is how my regex expression looks like. It takes everything between last - and one before it:</p>
  
  <pre><code>"([^-]+)(?=-[^-]+-?$)"
  </code></pre>
  
  <p>I am trying capture 12345 in a variable without loop:</p>
  
  <p>This is how my code looks like:</p>
  
  <pre><code>string output = Regex.Replace("A1-BC-12345-D2", @"([^-]+)(?=-[^-]+-?$)", "$1");
  </code></pre>
  
  <p>output looks same as input.</p>
  
  <p>I have verified the regex on regex101.com and it is capturing the right values.</p>
  
  <p>How do i get 12345 in the output using capture group?</p>
  
  <h2>Edit</h2>
  
  <p>I cannot use <code>Match</code> or loop through as I am trying to use this in AD FS Claims Rule which only supports <code>Replace</code></p>