正则表达式模式失败

时间:2014-09-02 16:33:11

标签: c# regex

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();

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

1 个答案:

答案 0 :(得分:0)

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

<强>代码:

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();

文件数据:

Born    
Mahomedali Jinnahbhai 25 December 1876 Karachi, British India 
Died 11 September 1948 Karachi, Pakistan 
Political party 
Indian National Congress (1906–20) 
All-India Muslim League (1913–47) 
Muslim League (1947–48)
Pakistan came into being on 14 August 1947
not on 10 august 1947

<强>输出:

enter image description here

我希望你能从解释中得到一些东西。