Adam Soffer
Adam Soffer

Reputation: 1654

Regular Expression - All words that begin and end in different letters

I'm having trouble with this regular expression:

Construct a regular expression defining the following language over alphabet Σ = { a,b }

L6 = {All words that begin and end in different letters}

Here are some examples of regular expressions I was able to solve:

1. L1 = {all words of even length ending in ab} 
   (aa + ab + ba + bb)*(ab) 

2. L2 = {all words that DO NOT have the substring ab}
   b*a*  

Upvotes: 1

Views: 6192

Answers (4)

Raazia Bajwa
Raazia Bajwa

Reputation: 1

(aa+ab+ba+bb)∗(a+b)ab

It can choose any number of even length and have any character from a and b, and then end at string ab.

Upvotes: 0

Ali Sajid
Ali Sajid

Reputation: 1

1- Write a Regular expression for each of the following languages: (a)language of all those strings which end with substrings 'ab' and have odd length. (b)language of all those strings which do not contain the substring 'abb'.

2- Construct a deterministic FSA for each of the following languages: (a)languages of all those strings in which second last symbol is 'b'. (b)language of all those strings whose length is odd,but contain even number if b's.

Upvotes: 0

Op De Cirkel
Op De Cirkel

Reputation: 29473

Would this work:

(a.*b)|(b.*a)

Or said in Kleene way:

a(a+b)*b+b(a+b)*a

Upvotes: 3

Petar Ivanov
Petar Ivanov

Reputation: 93020

This should do it:

"^((a.*b)|(b.*a))$"

Upvotes: 1

Related Questions