Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 正则表达式模式失败_C#_Regex - Fatal编程技术网

C# 正则表达式模式失败

C# 正则表达式模式失败,c#,regex,C#,Regex,在输出中,我得到了一些类似于上述模式的日期,但是Regex.Match没有提取我的所有日期。我该怎么办?我重新创建了您的问题,一切都很好 代码: string[] data=File.ReadAllLines(@"D:\\data.txt"); string pattern = @"\d{1,2} " + @"\w{1,9} " + @"\d{4}"; foreach (string operand in data) { Console.WriteLin

在输出中,我得到了一些类似于上述模式的日期,但是
Regex.Match
没有提取我的所有日期。我该怎么办?

我重新创建了您的问题,一切都很好

代码:

string[] data=File.ReadAllLines(@"D:\\data.txt");

string pattern = @"\d{1,2} " + @"\w{1,9} " + @"\d{4}";

foreach (string operand in data)
{               
    Console.WriteLine(Regex.Match(operand,pattern));
}

Console.ReadLine();
string[] data = File.ReadAllLines(@"D:\\data.txt");

string pattern = @"\d{1,2} " + @"\w{1,9} " + @"\d{4}";

foreach (string operand in data)
{
    Console.WriteLine(Regex.Match(operand, pattern));
}

Console.ReadLine();
文件数据:

string[] data=File.ReadAllLines(@"D:\\data.txt");

string pattern = @"\d{1,2} " + @"\w{1,9} " + @"\d{4}";

foreach (string operand in data)
{               
    Console.WriteLine(Regex.Match(operand,pattern));
}

Console.ReadLine();
string[] data = File.ReadAllLines(@"D:\\data.txt");

string pattern = @"\d{1,2} " + @"\w{1,9} " + @"\d{4}";

foreach (string operand in data)
{
    Console.WriteLine(Regex.Match(operand, pattern));
}

Console.ReadLine();
输出:

string[] data=File.ReadAllLines(@"D:\\data.txt");

string pattern = @"\d{1,2} " + @"\w{1,9} " + @"\d{4}";

foreach (string operand in data)
{               
    Console.WriteLine(Regex.Match(operand,pattern));
}

Console.ReadLine();
string[] data = File.ReadAllLines(@"D:\\data.txt");

string pattern = @"\d{1,2} " + @"\w{1,9} " + @"\d{4}";

foreach (string operand in data)
{
    Console.WriteLine(Regex.Match(operand, pattern));
}

Console.ReadLine();


我希望您能从解释中得到一些信息。

这有什么“不起作用”哪些示例值没有被提取?它没有从文件中提取所有日期。失败的日期是否都在“九月”(每个正则表达式的名称中有10个字符,而不是9个字符)中,或者它们是否有不同数量的空格?请尝试提取日期,然后使用DateTime.Parse()谢谢,伙计,我觉得文本文件格式弄乱了我的代码。