http://qs1969.pair.com?node_id=197193


in reply to Regex refresher

Hello!

Cool thread :) ... but can somebody help me out please? I think my understanding/knowledge of regex's is sorely lacking because I'm not able to follow the descriptions in the answers above! To explain my problem...

First of all, the original answers I came up with on paper before looking at anyone else's replies were...
"", 01, 11, 0001, 1001, 00101, 10101, 000001, 100001, 001101
... which I'm assuming are the incorrect 10 from looking at the posts above and the amount of experience the posters share compared to me! :)

I wrote a little program which spits out the first answers in agreement with abell's answer above, but not in agreement with dws's.

I think my stumbling block is understanding how the regex /(0|1(01*0)*1)*/ matches the 00? Could somebody explain this to me? I've read a lot of the references but in my mind I'm looking at it like this...

<Incorrect, Please Explain Why?>
1) I take the 0|1 and figure that (except for the empty string) it will match any string that begins 0 or 1.
2) I take the (01*0)* and figure that it will match nothing, 00 or 0x0 where x is an arbitrary number of 1's.
3) I assume the last 1 means there has to be a 1 at the end of the regex?! I know this is wrong from the answers I'm getting back but I don't know why! argh!
</Incorrect, Please Explain Why?>

Scratching his head and hoping for help,
Neil

UPDATE: I think zakb has hit the nail on the head for me with his answer :) ... Wow! Do I feel silly now ;)
I *think* if you add the brackets that I was interpreting around the 0|1 combination it makes the answers I came up with correct :) Of course it doesn't help you spot the pattern that no longer exists ;)