title: C# Regex Performance very slow
body: <p>I am very new in regex topic. I want to parse log files with following regex:</p>
  
  <pre><code>(?&lt;time&gt;(.*?))[|](?&lt;placeholder4&gt;(.*?))[|](?&lt;source&gt;(.*?))[|](?&lt;level&gt;[1-3])[|](?&lt;message&gt;(.*?))[|][|][|](?&lt;placeholder1&gt;(.*?))[|][|](?&lt;placeholder2&gt;(.*?))[|](?&lt;placeholder3&gt;(.*))
  </code></pre>
  
  <p>A log line looks like this:</p>
  
  <pre class="lang-none prettyprint-override"><code>2001.07.13 09:40:20|1|SomeSection|3|====== Some log message::Type: test=sdfsdf|||.\SomeFile.cpp||60|-1
  </code></pre>
  
  <p>A log file with appr. 3000 lines takes very long to parse it. Do you have some hints to speed up the performance? Thank you...</p>
  
  <p><strong>Update:</strong>
  I use regex because I use different log files which do not have the same structure and I use it that way:</p>
  
  <pre><code>string[] fileContent = File.ReadAllLines(filePath);
  Regex pattern = new Regex(LogFormat.GetLineRegex(logFileFormat));
  
  foreach (var line in fileContent)
  {
     // Split log line
     Match match = pattern.Match(line);
  
     string logDate = match.Groups["time"].Value.Trim();
     string logLevel = match.Groups["level"].Value.Trim();
     // And so on...
  }
  </code></pre>
  
  <p><strong>Solution:</strong><br>
  Thank you for help. I've tested it with following results:<br><br>
  1.) Only added RegexOptions.Compiled:<br>
  <strong>From 00:01:10.9611143</strong> to 00:00:38.8928387<br><br>
  2.) Used Thomas Ayoub regex<br>
  From 00:00:38.8928387 to 00:00:06.3839097<br><br>
  3.) Used Wiktor Stribiżew regex<br>
  From 00:00:06.3839097 <strong>to 00:00:03.2150095</strong><br></p>