C#正则表达式发出“无法识别的转义序列”
|
我正在使用的正则表达式有问题,但不知道如何继续使用它们。我收到错误“无法识别的转义序列”。
我正在尝试列出下面代码中列出的格式的所有可能具有电话号码的文件
static void Main(string[] args)
{
//string pattern1 = \"xxx-xxx-xxxx\";
//string pattern2 = \"xxx.xxx.xxxx\";
//string pattern3 = \"(xxx) xxx-xxxx\";
string[] fileEntries = Directory.GetFiles(@\"C:\\BTISTestDir\");
foreach (string filename in fileEntries)
{
StreamReader reader = new StreamReader(filename);
string content = reader.ReadToEnd();
reader.Close();
string regexPattern1 = \"^(\\d{3}\\.){2}\\d{4}$\";
string regexPattern2 = \"^((\\(\\d{3}\\) ?)|(\\d{3}-))?\\d{3}-\\d{4}$\";
if(Regex.IsMatch(content, regexPattern1))
Console.WriteLine(\"File found: \" + filename);
if(Regex.IsMatch(content, regexPattern2))
Console.WriteLine(\"File found: \" + filename);
}
Console.WriteLine(Environment.NewLine + \"Finished\");
Console.ReadLine();
}
任何帮助深表感谢。
没有找到相关结果
已邀请:
3 个回复
味芯憨
使字符串不再使用转义字符
:
顺便说一句,我认为您希望最后的两个
是一个单独的ѭ4the,且两个条件之间有或(
)。
翱抹村
碧肮械淌设