regex powershell doesnt working, but works in regex101 [duplicate]

I have strings in the following format

    _AUTO_(123,SomeString)

and I am trying to extract 123 from the above string using regex. The regex, that I am using is:

    const string pattern = @"\_AUTO\_\(?<number>(\d)+\,";
    foreach(Match match in Regex.Matches(line, pattern)) { 
       Console.WriteLine(match.Groups["number"].Value); 
    } 

I am getting Unrecognized escape sequence \_ error exception. Could someone please point me what I am doing wrong?

Thanks!


You don't need to escape the underscore (or, for that matter, the comma). Change your regex to:

@"_AUTO_\(?<number>(\d)+,"