C#正则表达式,无法识别的转义序列 [英] C# Regex, Unrecognized escape sequence
本文介绍了C#正则表达式,无法识别的转义序列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下格式的字符串
_AUTO_(123,SomeString)
我正在尝试使用正则表达式从上述字符串中提取123。我正在使用的正则表达式是:
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);
}
我收到无法识别的转义序列\_错误异常。 b $ b有人可以指出我在做什么吗?
I am getting Unrecognized escape sequence \_ error exception. Could someone please point me what I am doing wrong?
谢谢!
推荐答案
您不需要转义下划线(或者,逗号)。将正则表达式更改为:
You don't need to escape the underscore (or, for that matter, the comma). Change your regex to:
@"_AUTO_\(?<number>(\d)+,"
这篇关于C#正则表达式,无法识别的转义序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文