當運行下面的代碼CPU負載去的方式了,它需要一個很長時間在更大的文件:正則表達式極其緩慢大型文檔
string pattern = @"\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*";
Regex regex = new Regex(
pattern,
RegexOptions.None | RegexOptions.Multiline | RegexOptions.IgnoreCase);
MatchCollection matches = regex.Matches(input); // Here is where it takes time
MessageBox.Show(matches.Count.ToString());
foreach (Match match in matches)
{
...
}
任何想法如何加快步伐?
你能量化「長時間」嗎? –
在大型文件上,每個文件最多可能需要1分鐘 – Jacqueline
多大? –