Regular expression translation.

77 Views Asked by At

Given a set {1,2,...9} how can I construct a regular expression starts with a 3 has no 8's and has even number of 6's? Here's what I tried: $$$$ Define a new set no8 = {1,2,3,4,5,6,7,9} $$3(6(no8)*)^2$$ Is this legal? I just cannot find another way to indicate that 8 should not be in the strings that are formed.

2

There are 2 best solutions below

1
On BEST ANSWER

3 ([1-579]* 6[1-579]* 6)* [1-579]*

where [1-579] denotes one of {1,2,3,4,5,7,9}.

7
On

As per your last thread, note the syntax $(x + y)$ says to choose exactly one of $x$ or $y$. So let's define $(1 + 2 + 3 + 4 + 5 + 6 + 7 + 9)$. Notice how I concatenate two $6$'s together. Now if I take $3((1 + 2 + 3 + 4 + 5 + 6 + 7 + 9)^{*}6^{*}(1 + 2 + 3 + 4 + 5 + 6 + 7 + 9)^{*}6^{*})^{*}$, I get an even number of $6$'s, if there are any at all.

With your solution, I could not match $3866$, since the $6$ must come right after the $3$.