I'm looking for a way to find all overlapping regex hits in a given string when the regex is a combo of simple strings.
For example I'd like to get the following matches when searching for aaa|aaag:
aaaaggg //original string to search
aaa //match1 index=0
aaa //match2 index=1
aaag //match3 index=1
And one more example when searching for tt|aaa|aaag:
ttttaaaaggg //original string to search
tt //match0 index=0
tt //match1 index=1
tt //match2 index=2
aaa //match3 index=3
aaa //match4 index=4
aaag //match5 index=4
A javascript implementation preferred. Thank you!
EDIT: This is different than the suggested duplicate answer (Javascript Regex - Find all possible matches, even in already captured matches) because I want to detect overlaps with the SAME index. Here's a demo of the suggested solution NOT working here: https://jsbin.com/moferipibi/edit?html,js,console,output