Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Regex, Unrecognized escape sequence

Tags:

c#

regex

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!

like image 384
test123 Avatar asked Nov 08 '11 22:11

test123


1 Answers

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

@"_AUTO_\(?<number>(\d)+,"
like image 91
Dan Avatar answered Nov 07 '22 09:11

Dan