35.5k views
0 votes
Write regular expressions for the following languages:

a. The set of strings of 0's and 1's whose 10th symbol from the right is a 0.
b. The set of strings of 0's and 1's with at most one pair of consecutive 0's.

User RaduS
by
6.4k points

1 Answer

5 votes

Answer:

a) ^.{9}[0][0-1]*$

b) (?=.*^[0-1]*$)(?=.*^(?!.*00(.*00))).*

Step-by-step explanation:

You can check the expression with the code in python, please see the image with the expressions evaluated for different cases.

a) First, we check if the position number 10 contains a zero by using the expression .{9}[0] and then we check that the input contains just numbers from zero to one (binary numbers) by using [0-1]

b) To understand this expression we need to know that ?=.* helps us evaluate two different expression and if one of the two is false the result is false (and gate), the first expression to be evaluated is [0-1] an it checks that the input contains just numbers from zero to one, the second expression 00(.*00) checks that there is not more than one pair of zeros.

Write regular expressions for the following languages: a. The set of strings of 0's-example-1
User John Idasetima
by
5.9k points