I've been trying to use RegExp in JS to test a string for a certain count of a substrings. I would like a purely RegExp approach so I can combine it with my other search criteria, but have not had any luck.
As a simple example I would like to test a word if it has exactly 2-3 as.
| case | test string | expected result |
|---|---|---|
| 1 | cat |
false |
| 2 | shazam |
true |
| 3 | abracadabra |
false |
Most of my guesses at regex fail case 3. Example: ^(?<!.*a.*)((.*a.*){2,3})(?!.*a.*)$