title: EXC_BAD_ACCESS with NSRegularExpression matchesInString:
body: <p>I have a line of code in my app that uses a regular expression to find PGP Keys in a string of user input. </p>
  
  <pre><code>    NSArray *pgpKeyMatch = [pgpKeyRegex matchesInString:userInput
                                                  options:0
                                                    range:NSMakeRange(0, [userInput length])];
  </code></pre>
  
  <p>For most cases it works as expected. But I've run into a problem when a particularly long key is input (length of 334,629 instead of ~9,000). I get: <code>Thread 1: EXC_BAD_ACCESS(CODE=1, ADDRESS=0X8)</code> and the app crashes. </p>
  
  <p>I've tried using the Zombies instrument (which found nothing) and setting an Exception Breakpoint (which didn't yield any more information).</p>
  
  <p>Stepping through the code shows that the NSRange is created successfully, but something goes wrong later in the execution of matchesInString: .</p>
  
  <p>Does anyone have insight on what's causing this bad access? or why this is an issue only with this very long key? Below is a more complete excerpt of code:</p>
  
  <pre><code>NSString *userInput = self.inputKey.text;
  
  NSError *pgpKeyRegexError = NULL;
  NSRegularExpression *pgpKeyRegex = [NSRegularExpression regularExpressionWithPattern:@"(?:-----BEGIN PGP (?:PUBLIC|PRIVATE) KEY BLOCK-----)\n(?:(?:.*:.*)\n)*\n(?:[^-]|\n)*\n(?:-----END PGP (?:PUBLIC|PRIVATE) KEY BLOCK-----)"
                                                                               options:0
                                                                                 error:&amp;pgpKeyRegexError];
  
  
  
  NSArray *pgpKeyMatch = [pgpKeyRegex matchesInString:userInput
                                              options:0
                                                range:NSMakeRange(0, [userInput length])];
  </code></pre>