[Solved] Are regular expressions (0*1*)* and (0 + 1)* same? [closed]


No, they are not the same:

  • 0*1* matches any number of zeroes (including none) followed by any number of ones (including none). This is then repeated any number of times (including none) via ()*
  • 0 + 1 matches a mandatory single zero, then at least one or more spaces, then one more space, then a mandatory single one. Again, this is repeated any number of times via ()* like before.

So, the two match very different things the first one will match input like 000000 or 1111 because it has (essentially) an optional zero or one, so an input that only has a single of these is correct but not according to the second regex. While the second one will match input that has at least two or more spaces between the mandatory 0 and 1 characters but the first regex will reject that, since it does not allow spaces.

solved Are regular expressions (0*1*)* and (0 + 1)* same? [closed]