title: OutOfMemoryException in Regex Matches when processing large files
body: <p>I've got an exception log from one of production code releases.</p>
  
  <pre><code>System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
     at System.Text.RegularExpressions.Match..ctor(Regex regex, Int32 capcount, String text, Int32 begpos, Int32 len, Int32 startpos)
     at System.Text.RegularExpressions.RegexRunner.InitMatch()
     at System.Text.RegularExpressions.RegexRunner.Scan(Regex regex, String text, Int32 textbeg, Int32 textend, Int32 textstart, Int32 prevlen, Boolean quick)
     at System.Text.RegularExpressions.Regex.Run(Boolean quick, Int32 prevlen, String input, Int32 beginning, Int32 length, Int32 startat)
     at System.Text.RegularExpressions.MatchCollection.GetMatch(Int32 i)
     at System.Text.RegularExpressions.MatchEnumerator.MoveNext()
  </code></pre>
  
  <p>The data it tries to process was about 800KB.</p>
  
  <p>In my local tests it works perfectly fine. Have you ever seen similar behaviour, what can be the cause?</p>
  
  <p>Shall I split the text before processing it, but obviously in that case regex might not match because the original file split from a random place. </p>
  
  <p><strong>My Regexes:</strong></p>
  
  <p><strong>EDIT 2 :</strong> </p>
  
  <p>I think this particular RegEx is causing the problem, when I test it out in an isolated environment  it's eating the memory instantly.</p>
  
  <pre><code>((?:( |\.\.|\.|""|'|=)[\/|\?](?:[\w#!:\.\?\+=&amp;@!$'~*,;\/\(\)\[\]\-]|%[0-9a-f]{2})*)( |\.|\.\.|""|'| ))?
  </code></pre>
  
  <p><strong>EDIT</strong> </p>
  
  <p>I was being wrong with my local test. I was loading up a big string then appending stuff to it which makes .NET Framework dizzy and then give an OOM exception during the RegEx instead of during string operations (or randomly, so ignore the previous stuff I've said).</p>
  
  <p><em>This is a .NET Framework 2.0 application.</em></p>