How to properly access the value of a capture group in C# regex? -


i have 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 1, printing _1. doing wrong?

you're getting value of whole match - want single group (group 1) can access via groups property , groupcollection indexer:

console.writeline(match.groups[1]); 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -