Write regular expressions for each of the following languages. a, = { a, b, c }
ID: 3813667 • Letter: W
Question
Write regular expressions for each of the following languages.
a, = { a, b, c } All strings that …
b, contain no more than two ‘c’s
c, start and end with the same character
d, have ‘c’s only in the middle (not at either end), and there is at least one ‘c’
e, contain ‘abc’
f, do not contain ‘aa’
g, contain only ‘b’s and are not empty
h, contain exactly two ‘a’s and exactly one ‘c’
i, have all ‘a’s (if any) before all ‘c’s (if any)
l, have ‘a’ in all even positions
k, begin with three matching characters (i.e., aaa…, bbb…, or ccc…)
Explanation / Answer
Ans : b .not more than 2 c's = (a* b* c a* b*c a* b* ) .....[* indicates occurances of one or many times for a character]
As c shouldnt be more than two times and there is no restriction on other characters .
c. start and end with the same charcter = ^abc$ .....[ ^ and $ indicates start and end with same charcters)
e. contain abc = a*b*c*(abc) ......... [the string should contain abc ]
h. exactly 2 a's and 1 c = aab*c .........(exactly 2 a's and one c no restriction on occurance of 'b').
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.