Seeking help with a regex task: Constructing a pattern for words over {a, b,c} with #a(w)≥2 and #b(w)≥2
c has no limitations
. Need solution assistance.
example for words that are in the language:
aaabbb
abbaba
bbaaab
ababab
baabba
abbaab
bbaaba
Thanks!
Shahar David is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
8
There are a number of ways to do this.
One approach is to consider the different possible ways that the word can start, and then see what must remain. You can, for example, break the possibilities into six cases:
- aa followed by a word with at least two b‘s
- aba followed by a word with at least one b
- aab followed by a word with at least one a
- baa followed by a word with at least one b
- bab followed by a word with at least one a
- bb followed by a word with at least two a‘s
I trust that you can take it from there?