I have the following code:
using System;
using System.Text.RegularExpressions;
public class Test
{
   public static void Main()
   {
      var r = new Regex(@"_(\d+)$");
      string new_name = "asdf_1";
      new_name = r.Replace(new_name, match =>
      {
         Console.WriteLine(match.Value);
         return match.Value;
         //return (Convert.ToUInt32(match.Value) + 1).ToString();
      });
      //Console.WriteLine(new_name);
   }
}
I expect match.Value to be 1, but it is printing as _1. What am I doing wrong?
 
  
                     
                        
You're getting the value of the whole Match - you only want a single group (group 1) which you can access via the Groups property and the GroupCollection indexer:
Console.WriteLine(match.Groups[1]);
 
                    See more on this question at Stackoverflow