title: Ruby Regex, get all possible matches (no clipping of the string)
body: <p>I have run into a problem with the ruby regex. I need to find all (potentially overlapping) matches. This is a simplification of the problem:</p>
  
  <pre><code>#Simple example
  "Hey".scan(/../)
  =&gt; ["He"] 
  #Actual results
  
  #With overlapping matches the result should be
  =&gt; ["He"], ["ey"]
  </code></pre>
  
  <p>The regex I am trying to execute and get all results for looks like this:</p>
  
  <pre><code>"aaaaaa".scan(/^(..+)\1+$/) #This looks for multiples of (here) "a" bigger than one that "fills" the entire string. "aa"*3 =&gt; true, "aaa"*2 =&gt; true. "aaaa"*1,5 =&gt; false.
   =&gt; [["aaa"]] 
  
  #With overlapping results this should be
   =&gt; [["aa"],["aaa"]]
  </code></pre>
  
  <p>Is there a library or a way to do regex in ruby to get the results I am after? </p>
  
  <p>I found some clues that this was possible in Perl, but after hours of research I did not find anything about a Ruby way of doing this. </p>
  
  <p>However I was able to find this "<a href="https://stackoverflow.com/questions/14863026/javascript-regex-find-all-possible-matches-even-in-already-captured-matches">Javascript Regex - Find all possible matches, even in already captured matches</a>", but I am not able to find anything similar for Ruby, nor find something similar to the last index property in the Ruby version. To be honest I don't think that it would have worked anyways since the regex I intend to use is recursive and relies on the entire string, while that method chops away at the string.</p>