I am counting the occurrence of specific keypairs in a word
console.log("acceptable".match(/ab|ac|ar/gi).length); //2
(picture) Example of just keypairs on regex101.com
This works as expected, but including anchored single letters, like "^a" overwrites other matches:
console.log("acceptable".match(/^a|ab|ac|ar/gi).length); //2, should be 3
(picture) Example of keypairs on regex101.com
As the regex101.com example shows, the ^a overwrites the ac match, so only 2 matches are found. I need to count every instance, even duplicates like "^a" as a substring of "ab". I can solve this without regex, but regex is more elegant.
Any help will be greatly appreciated.