Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

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

by TheDamian (Priest)
on Aug 23, 2002 at 13:06 UTC ( #192315=note: print w/replies, xml ) Need Help??

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

Can I just point out that a colon doesn't mean "don't tracktrack past this point". It means "don't backtrack *into* the preceding repetition (to try a different number of matches), but skip back over it instead".

And to answer the original question, x??: and x*?: are exactly the same as x<0> (except that x??: returns a scalar-ish match object, rather than the list-ish one returned by x*?: and x<0>).

Replies are listed 'Best First'.
Re: Re: Do nothing? or Do something important in a very obscure way?
by TimToady (Parson) on Aug 24, 2002 at 05:48 UTC
    More precisely, it means to means to ignore any decision points within the previous atom. Those decision points may or may not have been generated by a quantifier on the entire atom. For instance, in [a|b]: the colon disables trying the second alternative if the first alternative succeeds.
Re: Re: Do nothing? or Do something important in a very obscure way?
by BrowserUk (Pope) on Aug 23, 2002 at 13:44 UTC

    I'm not quite sure who said "don't tracktrack past this point" or even "don't backtrack past this point"? I know it wasn't me:)

    That leaves me with the same dilema though. What does x<0> mean?

    Does asking to match something exactly zero times mean:

    • Don't do anything?
    • Or: Don't accept an x here.
    • Or something else which I haven't underdstood?

    I'm only just getting to grips with Perl5 regexs, and have only used the 'simple' ones so far, but the idea of instructing the regex engine to match something zero times seems nonsensical to me at this stage. Unless it means "Fail if there is an x here", but that would be the same as [^x] or -[x] (or is that -<x>) in the new money?

    What's this about a "crooked mitre"? I'm good at woodwork!
      What does x<0> mean?

      It means "Don't do anything", or rather: "ignore that x". Just as x{0} does in Perl 5.

      Don't accept an x here?

      No. That's <!before x> in Perl 6. Or (?!x) in Perl 5.

      Which is not the same as "Accept something that isn't an x". That would be <-[x]> in Perl 6 and [^x] in Perl 5.

        Precisely. Let's ignore the syntax and mechanics, and re-examine the question (just in case it's helpful):

        A regex is a way to find something in something else. When building one, you have to consider carefully what it is you're trying to find, as well as where you're trying to find it.

        The root of this confusion was, "Why would I want to find none of something?"

        If you've got an irregular something to find, based around regular features, you would want to find none of the irregular (but expected) things, all of the regular features, and would want to be able to fail on unexpected irregularities.

        Similarly, if you've got something you want to find "no matter what", you could try to find it with no whitespace or punctuation (so that "important" would be the same as "*important*" and "I!M!P!O!R!T!A!N!T" and suchlike).

        These are probably bad examples, as I do not write complicated regexes myself, but I think the context is correct.

        Skipping over the notion that I can't actually see why anyone would write "Oh here's an x, just ignore it!" unless there is some way to have n in x<n> (x{n}) supplied by a variable such that it read ignore this if n==0, having demonstrated my lack of expertise with regexes, I'm prepared to accept that the construction may have uses I am unaware of.

        Thankyou, it's been an educaton.

        I look forward to Perl6 Grammers and Rules with relish.

        What's this about a "crooked mitre"? I'm good at woodwork!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://192315]
[stevieb]: choroba my GPS home device is done, at least prototype v1 is. I'm just making sure all of my code does what it says now
[stevieb]: I test/prototype code on my Pi, then I migrate it over to Arduino when it's ready (if that's a better platform for what I'm doing). The whole RPi stuff was for learning at first, then it snowballed. I'm just trying to get my in-house CI...
[stevieb]: ...done, which obviously requires a specific hardware setup.
[stevieb]: I don't write tests for the lower-level distributions (ie. ICs, sensors etc) within those distributions, I have all tests in a master distribution which encompasess all of the sub-modules

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2017-06-25 22:58 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (572 votes). Check out past polls.