I want to find all matches within a given string including overlapping matches. How could I achieve it?
# Example \"a-b-c-d\".???(/\\w-\\w/) # => [\"a-b\
Use capturing inside a positive lookahead:
"a-b-c-d".scan(/(?=(\w-\w))/).flatten # => ["a-b", "b-c", "c-d"]
See Ruby demo