Regular Expression Problem

What is a regular expression for the language 0 m 1 n where m + n is even?

+6
regex regular-language
source share
2 answers

If you mean the line 000...111... where the line length is even, can you use ^(00)*(01)?(11)*$

+14
source share

Good, so you need to consider for zero cases where there are odd and even. This requires two states: one for even zeros, one for odd zeros. Then for the case with an odd zero, you need to have 1 one, and then an even number of units. For an even case, you just need an even number.

It's easy to write DFA, but I don't know how to do this, so I'm going to question the regex:

 (0 (00)* 1 (11)*) \/ (00)*(11)* 
+1
source share

All Articles