• retagged by
1,297 views
0 0 votes
Write a regular expression for all strings of 0’s and 1’s in which there is an even number of 0’s between any two 1’s.

3 Answers

0 0 votes
$(0^{*} + 1(00)^{*}1)^{*}$  + $0^{*}10^{*}$
• edited by
0 0 votes
$0^{*}(1(00 + 1)^{*} (0 + \epsilon ) + \epsilon)$
–1 –1 vote

Here is a regular expression that will match all strings of 0's and 1's in which there is an even number of 0's between any two 1's:

^(1(00)*1)*$

 

Explanation:

  • ^ and $ anchor the regular expression to the start and end of the string, respectively. This ensures that the regular expression will only match the entire string and not just a substring.

  • 1 matches the character 1.

  • (00)* matches zero or more occurrences of the characters 00. This matches an even number of 0's.

  • (1(00)*1)* matches zero or more occurrences of a 1 followed by an even number of 0's followed by a 1. This ensures that there is an even number of 0's between any two 1's.

     

    For example, this regular expression would match the following strings:

  • 1
  • 11
  • 10001
  • 10010001
  • And it would not match the following strings:

  • 0
  • 10
  • 101
  • 1001
  • 1000101
  •  
  • 100010001
Position:
Show:

Related questions

0 0 votes
1 1 answer
485
485 views
moe12leb asked Nov 27, 2022
485 views
Write a regular expression for all strings of 0’s and 1’s in which the total number of zeros to the right of each 1 is even.
1 1 vote
0 0 answers
341
341 views
moe12leb asked Nov 27, 2022
341 views
Write a regular expression for all strings of 0’s and 1’s in which at least one copy of the substring 01 occurs before any copy of the substring 10 occurs in the string. ...
0 0 votes
1 1 answer
733
733 views
moe12leb asked Nov 4, 2022
733 views
does this string ‘baab’ belongs (ba)* U (ab)* ?