Describe as a regular expression the set of strings over {a,b,c} that contain the substrings aa,bb,cc

3.8k Views Asked by At

What would be an appropriate regular expression for this set of strings listed in my title? i have this so far:

(aa,bb,cc) is a subset of all the strings listed (a,b,c) (it corresponds to the strings over the alphabet (a,b,c))

i was wondering could somebody tell me the correct regular expression for this or tell me if i am on the right track.

Thanks

2

There are 2 best solutions below

0
On BEST ANSWER

If you want a regular expression for strings that contain ALL of your substrings aa bb and cc in the string then one way is to take all orderings of these three substrings, and for each ordering, say aa,bb,cc then the regular expression would be $(\Sigma^*) (aa) (\Sigma^*) (bb) (\Sigma^*) (cc)( \Sigma^*)$ where $\Sigma$ is your alphabet.

0
On

The regular expression you are looking for is $$(a+b+c)^*aa(a+b+c)^*bb(a+b+c)^*cc(a+b+c)^*$$

Using this regular expression you can form any word $w$ over the alphabet $\{a,b,c\}$ that contains the substring $aa$, $bb$, $cc$.