-3

what strings are accepted by this expression (0|10)* regular expression? I was thinking 0, 10, and was wondering if it would accept something like 010 since it is an or?

Thanks

Anony
  • 27
  • 3

2 Answers2

0

Well, the * at end signifies zero and unlimited times, so it will match an infinite number of strings. However, matches will be broken up by 2 1s in a row, or a 1 without a zero before or after it (if your alphabet is only 0 and 1).

Check out some examples here

So to answer the specific example in your question, 010 will be matched, as the regex will find 0, and then 10.

user3483203
  • 45,503
  • 8
  • 43
  • 75
  • Thanks for this! :) So as long as there is a * outside the brackets I can combine them? What if there is no * outside the brackets, they cannot be combined, eg 010? – Anony Mar 25 '18 at 04:08
  • If you don't include a star, `010` will still return a match, but it will be 2 matches, one for `0` and one for `10`. With the star, `010` is a single match. – user3483203 Mar 25 '18 at 04:10
  • So a 010 will not be accepted by a language that accepts L(0|10)? – Anony Mar 25 '18 at 04:33
  • @Anony This answer is correct. Here are some more examples: https://regex101.com/r/k0DV25/1 – mickmackusa Mar 25 '18 at 04:57
  • Thanks for your help! – Anony Mar 25 '18 at 05:18
-1

No JavaScript will not accept 010 because it is a or statement:

(0 | 10) is the same as 0 or 10 and so it will only accept 0 and 10

if you want it to also accept 010 then change it into (0 | 10 | 010)

Hope this helps!