I am trying to locate patterns in strings where a character is followed by another character, and then followed by the first character again.
For instance, in the string "abab" I am looking for "aba" and "bab".
/([a-z])[a-z]{1}\1/g
But when I run this code, it only returns the first result (I am working with JavaScript).
"abab".match(/([a-z])[a-z]{1}\1/g)
["aba"]
When I try with "ababcb", it gives two matches instead of three (I should get "aba", "bab", "bcb").
"ababcb".match(/([a-z])[a-z]{1}\1/g)
["aba", "bcb"]
I suspect the regex is repeating on the truncated string, finding the first match and then proceeding with the rest. How can I prevent this behavior and find all possible matches?