Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Re: Re: Re: Regex refresher (help?)

by zakb (Pilgrim)
on Sep 13, 2002 at 09:14 UTC ( #197486=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Re: Regex refresher (help?)
in thread Regex refresher

See FoxtrotUniform's answer above. 101 is not matched.

As for your other problems, here's a solution to one of them which should help with the others:

For reference, the original regex was:

/^(0|1(01*0)*1)*$/

Let's take your first example: 0011. 0 matches the first branch, and the final asterisk right at the end makes that greedy, so it also matches the second 0. 1 matches the second branch, the (01*0) matches nothing - which is ok because of the asterisk right after it. This effectively reduces the second branch to 1*1, which matches 11.

The others (1100, 0110) are variations on this theme.

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: Regex refresher (help?)
by charnos (Friar) on Sep 13, 2002 at 12:44 UTC
    g'ah! I know it's no excuse, but I was on my way out from work when I posted, and for some reason got it stuck in my head that the outer ()* would only match repetition, i.e. 0 could be matched, but if you matched the leading 0, then the next match would have to be 0. Likewise if the pattern matched 11, it would have to match from the right side of the | again. *sigh* ++zakb, I needed that. :P

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://197486]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2020-12-06 01:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How often do you use taint mode?





    Results (65 votes). Check out past polls.

    Notices?