using System;
using System.IO;
using System.Reflection;
using System.Text.RegularExpressions;
namespace regex
{
class MainClass
{
public static void Main(string[] args)
{
Regex exp = new Regex(@"e(-)?m[a@]il(s)?|input|output|padr(ão|ões)|máquina(s)?|reconhecimento",
RegexOptions.IgnoreCase | RegexOptions.Compiled |
RegexOptions.Multiline | RegexOptions.ExplicitCapture);
for (int filecount = 0 ; filecount < 22 ; filecount++)
{
string file = "/home/files/file"+ string.Format("{0:0#}",filecount) + ".txt";
StreamReader reader = new StreamReader(file);
string text = reader.ReadToEnd();
int c=0;
MatchCollection matchList = exp.Matches(text);
c = matchList.Count;
Console.WriteLine("Reading " + file + " -> " + c + " matches");
}
}
}
}
Если я закомментирую строку
c = matchList.Count;
это довольно быстро. Но мне нужно знать количество найденных совпадений.
Это самый быстрый способ сделать это? Для группы файлов, которая у меня есть, у меня уходит 14 секунд на анализ каждого файла. Perl занимает 1 секунду, чтобы вывести точно такую же информацию.
PS: каждый файл (текстовый файл) имеет +/- 1 МБ, поэтому для обработки требуется ~ 20 МБ.
Спасибо;)