Regular expression

83 Views Asked by At

I'm trying to find Strings of length 4 In this regular expression. However, I'm having trouble understanding how the string is built

$$1(1+00)^*0+(01)^*+(101+0)(10+λ)1^*$$

For example,

for $1(1+00)^*0$, if I decide that * gives me 1 or more I should get $1000$. But if I say * gives me nothing, would that mean that the string is $10$ or is it just $0$? Is my logic correct?

Does the * only affect whats in the brackets or does it affect everything behind it?

Here's an example string That I came up with (This is in regards to the whole expression): $$1001$$

1

There are 1 best solutions below

11
On BEST ANSWER

By convention, the Kleene star oprator $(\cdots)^*$ binds very strongly -- it applies only to the thing immediately before it, unless brackets are used to draw more in.

So $1(1+00)^*0$ means "a 1, followed by zero or more things that are each either 1 or 00, followed by a 0".

Your example 1001 is not matched by the regular expression. In particular it is not matched by $1(1+00)^*0$, because that can only generate strings that end with 0.