Reputation: 14185
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!
Upvotes: 8
Views: 10535
Reputation: 10786
You don't need to escape the underscore (or, for that matter, the comma). Change your regex to:
@"_AUTO_\(?<number>(\d)+,"
Upvotes: 16