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()谢谢,伙计,我觉得文本文件格式弄乱了我的代码。