title: Ruby: Find first N regex matches in a string (and stop scanning)
body: <p>Wanting to scan a very long string for regex matches. Wondering what would be the most efficient way to find the first N regex's. e.g. Something like:</p>
  
  <pre><code>'abcabcabc'.scan /b/, limit: 2
  </code></pre>
  
  <p>would end successfully after 5 characters, if only scan supported a limit option.</p>
  
  <p>(The string is several MB - a memoized data structure in memory - and this is a web request. Perf matters.)</p>