テキストファイルにいくつかの文字列があるかどうかを単純にチェックする方法がありますが、テキストドキュメントに存在するにもかかわらず、いくつかの文字列が一致として選択されていません。この例では見つからない問題のある文字列を含めました。
static void Main(string[] args)
{
string str = @"1009 10.32.0.28 03/05/2012 09:11:48 The license expires in 1192 day(s).";
StreamReader sr = new StreamReader(@"event_history.txt");
string allRead = sr.ReadToEnd();
sr.Close();
string regMatch = str;
if (Regex.IsMatch(allRead, regMatch))
{
Console.WriteLine("found\n");
}
else
{
Console.WriteLine("not found\n");
}
Console.ReadKey();
}
event_history.txt
1009 10.32.0.28 03/05/2012 09:11:48 The license expires in 1192 day(s).
正規表現の一致を「testing」と置き換えてから、「testing」をテキストファイルに追加すると、問題なく一致として取得されます:S