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
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
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 1
s 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
.
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!