Beefy Boxes and Bandwidth Generously Provided by pair Networks BBQ
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Do nothing? or Do something important in a very obscure way?

by blakem (Monsignor)
on Aug 23, 2002 at 10:49 UTC ( #192299=note: print w/ replies, xml ) Need Help??


in reply to Do nothing? or Do something important in a very obscure way?

/x?/ means match x zero or one times, but prefer 1...
i.e. Match it if you can

/x??/ means match x zero or one times, but prefer 0...
i.e. Match it if you have to

For instance:

% perl -le '"wxy" =~ /(wx?)/; print $1' 1:wx % perl -le '"wxy" =~ /(wx??)/; print $1' 1:w % perl -le '"wxy" =~ /(wx?y)/; print $1' 1:wxy % perl -le '"wxy" =~ /(wx??y)/; print $1' 1:wxy
The notation is a little confusing because the two question marks in a row mean different things. /x?/ is really just syntatic sugar for /x{0,1}/. The second question mark turns on min matching. When you look at it this way, the difference between /x{0,1}/ and /x{0,1}?/ should be more clear.

-Blake


Comment on Re: Do nothing? or Do something important in a very obscure way?
Select or Download Code
Re: Re: Do nothing? or Do something important in a very obscure way?
by BrowserUk (Pope) on Aug 23, 2002 at 10:58 UTC

    Makes sense in terms of Perl5 regex's, but in the original context of Exegesis5 where the 'x??' and 'x*?' are followed by the Perl6 'don't backtrack' ':' operator, I am not so sure?


    What's this about a "crooked mitre"? I'm good at woodwork!
      Ah, I see now.... /x??:/ will behave exactly like /x{0}/
      In english /x??:/ would read something like this:

      Match 'x' zero or one times, prefer 0 over 1, lock in the first value that allows this atom to match (i.e. don't backtrack).

      Since the 0 will always cause the atom to match, the engine will never be allowed to try the 1.

      I know thats not the best description.... hope it helps.

      -Blake

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (10)
As of 2014-04-21 16:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (498 votes), past polls