Theory 为包含至少一个a和至少一个b的字母表{a,b,c)上的字符串集编写正则表达式

Theory 为包含至少一个a和至少一个b的字母表{a,b,c)上的字符串集编写正则表达式,theory,formal-languages,computation,Theory,Formal Languages,Computation,为字母表{a,b,c上包含至少一个a和至少一个b的字符串集编写正则表达式 我怎么回答这个问题呢?E*aE*b|bE*aE* E是sigma,所以字母表中的任何字符我都没有足够的分数来评论乔伊17的答案,但我不知道正则表达式如何接受字符串abc或cba 我最初提出了这个正则表达式: ( a+b+c* U a+c*b+ U b+a+c* U b+c*a+ U c*+a+b+ U c*b+a+ )+ 我认为这应该行得通,但看到乔伊17的答案,我想你也可以这样做: E = any letter in

为字母表{a,b,c上包含至少一个a和至少一个b的字符串集编写正则表达式

我怎么回答这个问题呢?

E*aE*b|bE*aE*


E是sigma,所以字母表中的任何字符我都没有足够的分数来评论乔伊17的答案,但我不知道正则表达式如何接受字符串abc或cba

我最初提出了这个正则表达式:

( a+b+c* U a+c*b+ U b+a+c* U b+c*a+ U c*+a+b+ U c*b+a+ )+
我认为这应该行得通,但看到乔伊17的答案,我想你也可以这样做:

E = any letter in Sigma
(E*a+E*b+|a+E*b+E*|b+E*a+E*|E*b+E*a+)+
For the regular expression there are various possibilities:-
Now,
exactly one a and one b (where a comes before b) - c* a c* b c*
exactly one a and one b (where b comes before a) - c* b c* a c*
We take this idea to the answer for more than one a and b:-
a comes before b
(c* a a* c* b b* c*) ;
b comes before a
(c* b b* c* a a* c*)
or there are intermmediate occurances of a and b :-
Let RE R=(a+b+c)* 
this is all possible occurences of a,b,c in all orders ;
Hence when a comes before b;
(R* a R* b R*);
when b comes before a;
(R* b R* a B*)

we take the union to get the final answer ( R* a R* b R* + R* b R* a R*) where R = (a + b + c)*