0

I have a question

Write down a regular expression for all binary strings that end with an even (nonzero) number of 0's.

So far I have come up with L = { (0/1)* (00)+ }

But it doesn't seem to work all the time. The (0/1)* can generate 0110 and the (00)+ will add 0110 00 - which doesn't make an ending of even number of 0's.

Can anyone help me with this?

Thanks

Leo
  • 565
  • 5
  • 20

4 Answers4

2

I see you are using + to denote a superscript + for 1 or many, and a forward slash to denote a normal plus for a union.

This would work:

L = { (0/1)* 1/E (00)+ }
RK2015
  • 397
  • 1
  • 3
  • 15
1

I've found the solution.

Its L = { (0/1)* 1/E (00)+ }

Leo
  • 565
  • 5
  • 20
0

This will work:

\b(([01]*1(0{2})+)|((00)+))\b

You can test it here

You can also check this similar problem:

Regex: Odd number of occurrences of a char

Community
  • 1
  • 1
Acsisr
  • 186
  • 1
  • 15
0

Per condition you stated in your problem. Shouldn't it be { (0/1)* 1(00)+ } ? * denotes 0 or more occurrences. Whereas + denotes one or more occurrences.

havish
  • 305
  • 1
  • 4
  • 11