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

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:

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!

Replies are listed 'Best First'.
Re: Re: Re: Do nothing? or Do something important in a very obscure way?
by TheDamian (Vicar) on Aug 23, 2002 at 17:50 UTC
    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!
        ...unless there is some way to have n in x<n> (x{n}) supplied by a variable...

        There is. And it's probably exactly what you would have expected: x<$n>

        Actually, what x{0} says is "succeed if there are zero x'es here". And that's always true, because we can always match none of something, even in an empty string. So basically, x{0} is a NOP, and so is x??: and x*?:.

        Makeshifts last the longest.