[Math] Even String of b’s Regular Expression

automata

I was able to find a regular expression over the language {a,b} for all strings containing an even number of b's: $$a^{*}(ba^{*}ba^{*})^{*}$$ However I have two questions pertaining to this regular expression.

  1. Shouldn't the group after the first $a$ have a $^{+}$ since this regular expression could select strings which have 0 b's?

  2. Maybe my understanding of regular expressions is flawed (in terms of actual regex statements), but I attempted to test this in a regex editor and it selects for strings such as $a$ and $aa$, which contain no b's. Is there just not a correlation between regular expressions and regex?

Best Answer

Zero is an even number. The string $aa$ contains an even number of $b$s. The empty string (which your RE matches) also contains an even number of $b$s.

Related Question