How to evaluate this regular expression?

185 views Asked by At

I'm just learning regular expressions, so I just want to make sure my understanding is correct.

01* mean 0 followed by 0 or more repetitions of 1.
1* + 01* means either 0 or more repetitions of 1 OR 0 followed by 0 or more repetitions of 1.

Am I right or is there something that I'm missing? Thanks.

2

There are 2 answers

0
Octoshape On BEST ANSWER

This seems correct to me. (Even thought I'm not a whiz in regular expressiony myself)

But here's a good tutorial you could check out. This one I found useful as well.

1
Gato On

The + in a regex doesn't mean OR but "one or more of"

So instead of 1* + 01* you would say:

1*|01*

which would mean either a (maybe zero length) string of ones, or a zero followed by (maybe a zero length) string of ones.

So it would match any of:

1
1111
0
011

But none of:

101
110
100001
001
00

The OR operator (vertical pipe) has a low precedence.