Idea. Given the string, return all the matches (with overlaps) and the text before these matches.
Example. For the text atatgcgcatatat
and the query atat
there are three matches, and the desired output is atat
, atatgcgcatat
and atatgcgcatatat
.
Problem. I use Ruby 2.2 and String#scan
method to get multiple matches. I've tried to use lookahead, but the regex /(?=(.*?atat))/
returns every substring that ends with atat
. There must be some regex magic to solve this problem, but I can't figure out the right spell.