title: How do I get the match data for all occurrences of a Ruby regular expression in a string?
body: <p>I need the <code>MatchData</code> for each occurrence of a regular expression in a string. This is different than the scan method suggested in <a href="https://stackoverflow.com/questions/80357/ruby-match-all-occurrences-of-a-regex">Match All Occurrences of a Regex</a>, since that only gives me an array of strings (I need the full MatchData, to get begin and end information, etc).</p>
  
  <pre><code>input = "abc12def34ghijklmno567pqrs"
  numbers = /\d+/
  
  numbers.match input # #&lt;MatchData "12"&gt; (only the first match)
  input.scan numbers  # ["12", "34", "567"] (all matches, but only the strings)
  </code></pre>
  
  <p>I suspect there is some method that I've overlooked. Suggestions?</p>